# acorn-umd

> Parse acorn ast for AMD, CommonJS, and ES6 definitions

Latest version **0.4.0** (published 2015-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install acorn-umd
pnpm add acorn-umd
yarn add acorn-umd
bun add acorn-umd
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2015-05-14 |
| First published | 2015-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | Graeme Yeates |
| Maintainers | megawac |
| Keywords | acorn, modules, ast, umd, es6 imports, commonjs, amd |

## Links

- npm: https://www.npmjs.com/package/acorn-umd
- Repository: https://github.com//acorn-umd
- Issues: https://github.com//acorn-umd/issues
- npm.io page: https://npm.io/package/acorn-umd

## Dependencies (4)

- [acorn](https://npm.io/package/acorn.md) ^1.0.0
- [lodash](https://npm.io/package/lodash.md) ^3.6.0
- [estraverse](https://npm.io/package/estraverse.md) ^4.1.0
- [es-lookup-scope](https://npm.io/package/es-lookup-scope.md) ^1.0.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2015-05-14
- 0.3.2 — 2015-04-06
- 0.3.1 — 2015-04-02
- 0.3.0 — 2015-04-02
- 0.2.2 — 2015-04-02
- 0.2.1 — 2015-03-31
- 0.2.0 — 2015-03-31
- 0.1.0 — 2015-03-23
- 0.0.0 — 2015-03-21

## README

# acorn-umd

Parse acorn ast for AMD, CommonJS, and ES6 definitions.

[![Travis build status](http://img.shields.io/travis/megawac/acorn-umd.svg?style=flat)](https://travis-ci.org/megawac/acorn-umd)
[![Test Coverage](https://codeclimate.com/github/megawac/acorn-umd/badges/coverage.svg)](https://codeclimate.com/github/megawac/acorn-umd)
[![Code Climate](https://codeclimate.com/github/megawac/acorn-umd/badges/gpa.svg)](https://codeclimate.com/github/megawac/acorn-umd)
[![Dependency Status](https://david-dm.org/megawac/acorn-umd.svg)](https://david-dm.org/megawac/acorn-umd)
[![devDependency Status](https://david-dm.org/megawac/acorn-umd/dev-status.svg)](https://david-dm.org//acorn-umd#info=devDependencies)

The Nodes created align as closely as possible with the nodes generated for acorns ES6 import nodes. Example below

```js
var acorn = require('acorn');
var umd = require('acorn-umd');

var code = `
    import {a, b, c as d} from 'library';
    import foo from 'foo-library';
    
    let _ = require('lodash');
`;

var ast = acorn.parse(code, {ecmaVersion: 6});
var imports = umd(ast, {
    es6: true, amd: false, cjs: true
});

console.log(imports);
```

```js
[
  { type: 'CJSImport',
    reference: 
     { type: 'VariableDeclaration',
       start: 87,
       end: 113,
       declarations: [Object],
       kind: 'let' },
    specifiers: [ [Object] ],
    start: 87,
    end: 113,
    source: 
     { type: 'Literal',
       reference: [Object],
       value: 'lodash',
       raw: '\'lodash\'',
       start: 103,
       end: 111 }
  },
  { type: 'ImportDeclaration',
    start: 5,
    end: 42,
    specifiers: [ [Object], [Object], [Object] ],
    source: 
     { type: 'Literal',
       start: 32,
       end: 41,
       value: 'library',
       raw: '\'library\'' }
  },
  { type: 'ImportDeclaration',
    start: 47,
    end: 77,
    specifiers: [ [Object] ],
    source: 
     { type: 'Literal',
       start: 63,
       end: 76,
       value: 'foo-library',
       raw: '\'foo-library\'' }
  }
]
```


# AMD Imports

```js
let code = `
  foo();
  define(['foo', 'unused-import'], function($) {
      return $();
  });
`;

let ast = acorn.parse(code, {ecmaVersion: 6});
let parsed = umd(ast, {
  es6: false, amd: true, cjs: false
});

console.log(parsed);

[
 {
  type: 'AMDImport',
  reference: { DEFINE_NODE },
  start: 12,
  end: 81,

  specifiers: [ { type: 'Identifier', start: 54, end: 55, name: '$' } ],
  sources: 
   [ { type: 'Literal',
       reference: [Object],
       value: 'foo',
       raw: '\'foo\'',
       start: 20,
       end: 25 },
     { type: 'Literal',
       reference: [Object],
       value: 'unused-import',
       raw: '\'unused-import\'',
       start: 27,
       end: 42 } ],

  // Grouped [source, variable] name array
  imports: [ [ {SOURCE_NODE}, {VARIABLE_NODE} ], [ {SOURCE_NODE}, undefined ] 
 }
]
```

#### Get the scope of a node


```
import {sample} from 'lodash'

let parsed = umd(ast, {
  es6: false, amd: true, cjs: false
});

let node = sample(parsed);

let scope = node.scope; // scope is null if global otherwise a function node
```

---
_Source: https://npm.io/package/acorn-umd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
