├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── babel.config.js ├── package.json ├── src ├── index.js └── walk.js └── test └── index.js /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | name: Run tests 8 | strategy: 9 | matrix: 10 | node-version: 11 | - '0.12' 12 | - '4.x' 13 | - '6.x' 14 | - '8.x' 15 | - '10.x' 16 | - '12.x' 17 | - '14.x' 18 | - '15.x' 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Checkout sources 22 | uses: actions/checkout@v2 23 | - name: Install Node.js ${{matrix.node-version}} 24 | uses: actions/setup-node@v2 25 | with: 26 | node-version: ${{matrix.node-version}} 27 | - name: Install dependencies 28 | run: npm install 29 | - name: Run tests 30 | run: npm test 31 | 32 | lint: 33 | name: Standard Style 34 | runs-on: ubuntu-latest 35 | steps: 36 | - name: Checkout sources 37 | uses: actions/checkout@v2 38 | - name: Install Node.js 39 | uses: actions/setup-node@v2 40 | with: 41 | node-version: 14.x 42 | - name: Install dependencies 43 | run: npm install 44 | - name: Check style 45 | run: npm run lint 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | package-lock.json 29 | 30 | lib/* 31 | /index.js 32 | /walk.js 33 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/browserify/acorn-node/dec0e341405ddc625122b93663dbf8bc3994bc7d/.npmignore -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # acorn-node change log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## 2.0.1 8 | * Fix crash on class methods named `static`: 9 | ```js 10 | class X { 11 | static () {} 12 | } 13 | ``` 14 | 15 | Thanks [@kumavis](https://github.com/kumavis)! 16 | 17 | ## 2.0.0 18 | * Use acorn's builtin dynamic `import()` parsing. This parses the `ImportExpression` node type instead of the `Import` node type from acorn-node 1.x. 19 | * Reject escape sequences in `import.meta`. 20 | 21 | ## 1.8.2 22 | * Revert a breaking change in import.meta parsing. 23 | 24 | ## 1.8.1 25 | * Fix crash in compiled private-class-elements code. 26 | 27 | ## 1.8.0 28 | * Upgrade acorn to v7. 29 | 30 | For backwards compatibility, `acorn-node` still uses the `Import` node type for dynamic imports, _NOT_ `ImportExpression` like acorn v7 and estree. 31 | * Add numeric separator support: 32 | ```js 33 | var a = 10_000_000_000_000_000_000_000_000n; 34 | ``` 35 | 36 | ## 1.7.0 37 | * Add class instance fields support: 38 | ```js 39 | class X { 40 | pub = 1; 41 | #priv = 2; 42 | } 43 | ``` 44 | * Add class static fields support: 45 | ```js 46 | class X { 47 | static pub = 1; 48 | static #priv = 2; 49 | } 50 | ``` 51 | * Add `export * as ns` support when `sourceType` is 'module': 52 | ```js 53 | export * as ns from './ns.mjs'; 54 | ``` 55 | 56 | ## 1.6.2 57 | 58 | * Allow dynamic `import()` in scripts. 59 | * Update minimum dependency versions, fixing a peerDependency warning. 60 | * Add Node 10 and 11 to CI. 61 | 62 | ## 1.6.1 63 | 64 | * Update acorn-dynamic-import to v4. 65 | 66 | ## 1.6.0 67 | 68 | * Upgrade acorn to v6. 69 | * Add bigint support. 70 | 71 | ## 1.5.2 72 | 73 | * Upgrade acorn to support optional catch binding in the AST walker. 74 | 75 | ## 1.5.1 76 | 77 | * Fix tests on Node <= 0.12. 78 | 79 | ## 1.5.0 80 | 81 | * Add tests for async iteration, optional catch binding, import.meta, 82 | dynamic import, bigint (currently unsupported). 83 | * Add import.meta support. (`sourceType: 'module'` only) 84 | * Add dynamic import support. (`sourceType: 'module'` only) 85 | * Fix optional catch binding support in the walker. 86 | 87 | ## 1.4.0 88 | 89 | * Upgrade acorn to 5.6, which supports optional catch bindings and other 90 | new syntax features. 91 | * Set ecmaVersion to 2019 to opt in to optional catch bindings etc. 92 | 93 | ## 1.3.0 94 | 95 | * Upgrade acorn to 5.4, which supports object spread and async iteration. 96 | * Remove acorn5-object-spread plugin. 97 | 98 | ## 1.2.0 99 | 100 | * Expose `acorn/dist/walk` as `acorn-node/walk`. 101 | 102 | ## 1.1.0 103 | 104 | * Enable `allowHashBang` and `allowReturnOutsideFunction` by default. 105 | 106 | ## 1.0.0 107 | 108 | * Initial release. 109 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # [Apache License 2.0](https://spdx.org/licenses/Apache-2.0) 2 | 3 | Copyright 2018 Renée Kooi 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | > http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ## acorn-bigint 18 | 19 | The code in the `lib/bigint` folder is compiled from code licensed as MIT: 20 | 21 | > Copyright (C) 2017-2018 by Adrian Heine 22 | > 23 | > Permission is hereby granted, free of charge, to any person obtaining a copy 24 | > of this software and associated documentation files (the "Software"), to deal 25 | > in the Software without restriction, including without limitation the rights 26 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | > copies of the Software, and to permit persons to whom the Software is 28 | > furnished to do so, subject to the following conditions: 29 | > 30 | > The above copyright notice and this permission notice shall be included in 31 | > all copies or substantial portions of the Software. 32 | > 33 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 | > THE SOFTWARE. 40 | 41 | Find the source code at https://github.com/acornjs/acorn-bigint. 42 | 43 | ## acorn-import-meta 44 | 45 | The code in the `lib/import-meta` folder is compiled from code licensed as MIT: 46 | 47 | > Copyright (C) 2017-2018 by Adrian Heine 48 | > 49 | > Permission is hereby granted, free of charge, to any person obtaining a copy 50 | > of this software and associated documentation files (the "Software"), to deal 51 | > in the Software without restriction, including without limitation the rights 52 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | > copies of the Software, and to permit persons to whom the Software is 54 | > furnished to do so, subject to the following conditions: 55 | > 56 | > The above copyright notice and this permission notice shall be included in 57 | > all copies or substantial portions of the Software. 58 | > 59 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | > THE SOFTWARE. 66 | 67 | Find the source code at https://github.com/acornjs/acorn-import-meta. 68 | 69 | ## acorn-dynamic-import 70 | 71 | The code in the `lib/dynamic-import` folder is licensed as MIT: 72 | 73 | > MIT License 74 | > 75 | > Copyright (c) 2016 Jordan Gensler 76 | > 77 | > Permission is hereby granted, free of charge, to any person obtaining a copy 78 | > of this software and associated documentation files (the "Software"), to deal 79 | > in the Software without restriction, including without limitation the rights 80 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 81 | > copies of the Software, and to permit persons to whom the Software is 82 | > furnished to do so, subject to the following conditions: 83 | > 84 | > The above copyright notice and this permission notice shall be included in all 85 | > copies or substantial portions of the Software. 86 | > 87 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 88 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 89 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 90 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 91 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 92 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 93 | > SOFTWARE. 94 | 95 | Find the source code at https://github.com/kesne/acorn-dynamic-import. 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # acorn-node 2 | 3 | [Acorn](https://github.com/acornjs/acorn) preloaded with plugins for syntax parity with recent Node versions. 4 | 5 | It also includes versions of the plugins compiled with [Babel](https://github.com/babel/babel), so they can be run on old Node versions (0.6 and up). 6 | 7 | [![npm][npm-image]][npm-url] 8 | [![travis][travis-image]][travis-url] 9 | [![standard][standard-image]][standard-url] 10 | 11 | [npm-image]: https://img.shields.io/npm/v/acorn-node.svg?style=flat-square 12 | [npm-url]: https://www.npmjs.com/package/acorn-node 13 | [travis-image]: https://img.shields.io/travis/browserify/acorn-node/master.svg?style=flat-square 14 | [travis-url]: https://travis-ci.org/browserify/acorn-node 15 | [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 16 | [standard-url]: http://npm.im/standard 17 | 18 | ## Install 19 | 20 | ``` 21 | npm install acorn-node 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | var acorn = require('acorn-node') 28 | ``` 29 | 30 | The API is the same as [acorn](https://github.com/acornjs/acorn), but with plugins to match Node.js behaviour. 31 | 32 | - Currently no plugins are in use as the main `acorn` branch supports the same syntax as Node.js. 33 | 34 | The following options have different defaults from acorn, to match Node modules: 35 | 36 | - `ecmaVersion: 2022` 37 | - `allowHashBang: true` 38 | - `allowReturnOutsideFunction: true` 39 | 40 | ```js 41 | var walk = require('acorn-node/walk') 42 | ``` 43 | 44 | The Acorn syntax tree walker. Comes preconfigured for the syntax plugins if necessary. 45 | See the [acorn documentation](https://github.com/acornjs/acorn#distwalkjs) for details. 46 | 47 | ## License 48 | 49 | The files in the repo root and the ./test folder are licensed as [Apache-2.0](LICENSE.md). 50 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['@babel/preset-env', { 4 | spec: true 5 | }] 6 | ], 7 | plugins: [ 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "acorn-node", 3 | "description": "the acorn javascript parser, preloaded with plugins for syntax parity with recent node versions", 4 | "version": "2.0.1", 5 | "author": "Renée Kooi ", 6 | "bugs": { 7 | "url": "https://github.com/browserify/acorn-node/issues" 8 | }, 9 | "dependencies": { 10 | "acorn": "^8.8.2", 11 | "acorn-walk": "^8.2.0", 12 | "setprototypeof": "^1.2.0", 13 | "xtend": "^4.0.2" 14 | }, 15 | "devDependencies": { 16 | "@babel/cli": "^7.10.1", 17 | "@babel/core": "^7.10.1", 18 | "@babel/preset-env": "^7.10.1", 19 | "mkdirp": "^0.5.5", 20 | "npm-run-all": "^4.1.5", 21 | "standard": "^13.1.0", 22 | "tape": "^4.13.3" 23 | }, 24 | "homepage": "https://github.com/browserify/acorn-node", 25 | "keywords": [ 26 | "acorn", 27 | "browserify", 28 | "javascript", 29 | "parser" 30 | ], 31 | "license": "Apache-2.0", 32 | "main": "index.js", 33 | "repository": { 34 | "type": "git", 35 | "url": "https://github.com/browserify/acorn-node.git" 36 | }, 37 | "scripts": { 38 | "lint": "standard", 39 | "test": "node test", 40 | "prepare": "npm run build && node test", 41 | "build:self": "babel src --out-dir .", 42 | "build": "npm-run-all --parallel build:*" 43 | }, 44 | "standard": { 45 | "ignore": [ 46 | "lib/**/*" 47 | ] 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var acorn = require('acorn') 4 | 5 | var CJSParser = acorn.Parser 6 | // Required paths should be relative to the package root, because Babel outputs this file there. 7 | // .extend(require('./lib/acorn-class-fields')) 8 | // .extend(require('./lib/acorn-static-class-features')) 9 | .extend(defaultOptionsPlugin) 10 | var ESModulesParser = CJSParser 11 | 12 | function mapOptions (opts) { 13 | if (!opts) opts = {} 14 | return { 15 | ecmaVersion: 2022, 16 | allowHashBang: true, 17 | allowReturnOutsideFunction: true, 18 | ...opts 19 | } 20 | } 21 | 22 | function defaultOptionsPlugin (P) { 23 | return class DefaultOptionsParser extends P { 24 | constructor (opts, src) { 25 | super(mapOptions(opts), src) 26 | } 27 | } 28 | } 29 | 30 | function getParser (opts) { 31 | if (!opts) opts = {} 32 | return opts.sourceType === 'module' ? ESModulesParser : CJSParser 33 | } 34 | 35 | module.exports = exports = { 36 | ...acorn, 37 | Parser: CJSParser, 38 | ESModulesParser: ESModulesParser, 39 | 40 | parse: function parse (src, opts) { 41 | return getParser(opts).parse(src, opts) 42 | }, 43 | parseExpressionAt: function parseExpressionAt (src, offset, opts) { 44 | return getParser(opts).parseExpressionAt(src, offset, opts) 45 | }, 46 | tokenizer: function tokenizer (src, opts) { 47 | return getParser(opts).tokenizer(src, opts) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/walk.js: -------------------------------------------------------------------------------- 1 | var walk = require('acorn-walk') 2 | 3 | var base = { 4 | ...walk.base 5 | } 6 | 7 | function simple (node, visitors, baseVisitor, state, override) { 8 | return walk.simple(node, visitors, baseVisitor || base, state, override) 9 | } 10 | 11 | function ancestor (node, visitors, baseVisitor, state) { 12 | return walk.ancestor(node, visitors, baseVisitor || base, state) 13 | } 14 | 15 | function recursive (node, state, funcs, baseVisitor, override) { 16 | return walk.recursive(node, state, funcs, baseVisitor || base, override) 17 | } 18 | 19 | function full (node, callback, baseVisitor, state, override) { 20 | return walk.full(node, callback, baseVisitor || base, state, override) 21 | } 22 | 23 | function fullAncestor (node, callback, baseVisitor, state) { 24 | return walk.fullAncestor(node, callback, baseVisitor || base, state) 25 | } 26 | 27 | function findNodeAt (node, start, end, test, baseVisitor, state) { 28 | return walk.findNodeAt(node, start, end, test, baseVisitor || base, state) 29 | } 30 | 31 | function findNodeAround (node, pos, test, baseVisitor, state) { 32 | return walk.findNodeAround(node, pos, test, baseVisitor || base, state) 33 | } 34 | 35 | function findNodeAfter (node, pos, test, baseVisitor, state) { 36 | return walk.findNodeAfter(node, pos, test, baseVisitor || base, state) 37 | } 38 | 39 | function findNodeBefore (node, pos, test, baseVisitor, state) { 40 | return walk.findNodeBefore(node, pos, test, baseVisitor || base, state) 41 | } 42 | 43 | function make (funcs, baseVisitor) { 44 | return walk.make(funcs, baseVisitor || base) 45 | } 46 | 47 | exports.simple = simple 48 | exports.ancestor = ancestor 49 | exports.recursive = recursive 50 | exports.full = full 51 | exports.fullAncestor = fullAncestor 52 | exports.findNodeAt = findNodeAt 53 | exports.findNodeAround = findNodeAround 54 | exports.findNodeAfter = findNodeAfter 55 | exports.findNodeBefore = findNodeBefore 56 | exports.make = make 57 | exports.base = base 58 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var acorn = require('../') 3 | var walk = require('../walk') 4 | var baseAcorn = require('acorn') 5 | 6 | test('parses object spread syntax', function (t) { 7 | var ast = acorn.parse('var a = { ...b }') 8 | t.equal(ast.body[0].declarations[0].init.type, 'ObjectExpression') 9 | t.equal(ast.body[0].declarations[0].init.properties[0].type, 'SpreadElement') 10 | 11 | ast = acorn.parse('function a ({ ...b }) {}') 12 | t.equal(ast.body[0].params[0].type, 'ObjectPattern') 13 | t.equal(ast.body[0].params[0].properties[0].type, 'RestElement') 14 | 15 | t.end() 16 | }) 17 | 18 | test('does not change main acorn module', function (t) { 19 | t.throws(function () { 20 | baseAcorn.parse('return 10n', { ecmaVersion: 2022 }) 21 | }) 22 | t.end() 23 | }) 24 | 25 | test('tokenizes object spread syntax', function (t) { 26 | var tokenizer = acorn.tokenizer('var a = { ...b }') 27 | 28 | t.doesNotThrow(function (t) { 29 | while (tokenizer.getToken().type !== acorn.tokTypes.eof) {} 30 | }) 31 | t.end() 32 | }) 33 | 34 | test('allows hashbangs by default', function (t) { 35 | t.doesNotThrow(function () { 36 | acorn.parse('#!/usr/bin/env node\nconsole.log("ok")') 37 | }) 38 | t.end() 39 | }) 40 | 41 | test('allows top level return by default', function (t) { 42 | t.doesNotThrow(function () { 43 | acorn.parse('console.log("ok"); return; console.log("not ok")') 44 | }) 45 | t.end() 46 | }) 47 | 48 | test('supports async generators', function (t) { 49 | t.doesNotThrow(function () { 50 | acorn.parse('async function* a () { await x; yield 1 }') 51 | }) 52 | t.end() 53 | }) 54 | 55 | test('supports async iteration', function (t) { 56 | t.doesNotThrow(function () { 57 | acorn.parse('async function l (y) { for await (const x of y) {} }') 58 | }) 59 | t.end() 60 | }) 61 | 62 | test('supports optional catch', function (t) { 63 | t.doesNotThrow(function () { 64 | acorn.parse('try { throw null } catch {}') 65 | }) 66 | t.end() 67 | }) 68 | 69 | test('supports bigint', function (t) { 70 | t.doesNotThrow(function () { 71 | acorn.parse('50n ** 50n') 72 | }) 73 | t.end() 74 | }) 75 | 76 | test('supports numeric separators', function (t) { 77 | t.doesNotThrow(function () { 78 | acorn.parse('50_000_000n ** 1n') 79 | }) 80 | t.end() 81 | }) 82 | 83 | test('supports import.meta with sourceType: module', function (t) { 84 | t.doesNotThrow(function () { 85 | acorn.parse('console.log(import.meta.url)', { sourceType: 'module' }) 86 | }) 87 | t.throws(function () { 88 | acorn.parse('console.log(import.m\\u0065ta.ul)', { sourceType: 'module' }) 89 | }, /must not contain escaped characters/) 90 | t.end() 91 | }) 92 | 93 | test('supports dynamic import() with sourceType: module', function (t) { 94 | t.doesNotThrow(function () { 95 | acorn.parse('import("./whatever.mjs")', { sourceType: 'module' }) 96 | }) 97 | t.end() 98 | }) 99 | 100 | test('supports dynamic import() with sourceType: script', function (t) { 101 | t.doesNotThrow(function () { 102 | acorn.parse('import("./whatever.mjs")', { sourceType: 'script' }) 103 | }) 104 | t.end() 105 | }) 106 | 107 | test('supports class instance properties', function (t) { 108 | t.doesNotThrow(function () { 109 | acorn.parse('class X { x = y }', { sourceType: 'script' }) 110 | }) 111 | t.end() 112 | }) 113 | 114 | test('supports private class instance properties', function (t) { 115 | t.doesNotThrow(function () { 116 | acorn.parse('class X { #x = y }', { sourceType: 'script' }) 117 | }) 118 | t.end() 119 | }) 120 | 121 | test('supports class static properties', function (t) { 122 | t.doesNotThrow(function () { 123 | acorn.parse('class X { static x = y }', { sourceType: 'script' }) 124 | }) 125 | t.end() 126 | }) 127 | 128 | test('supports class function named static', function (t) { 129 | t.doesNotThrow(function () { 130 | acorn.parse('class X { static () {} }', { sourceType: 'script' }) 131 | }) 132 | t.end() 133 | }) 134 | 135 | test('supports private class static properties', function (t) { 136 | t.doesNotThrow(function () { 137 | acorn.parse('class X { static #x = y }', { sourceType: 'script' }) 138 | }) 139 | t.end() 140 | }) 141 | 142 | test('supports namespace export syntax with sourceType: module', function (t) { 143 | t.doesNotThrow(function () { 144 | acorn.parse('export * as x from "./x.mjs";', { sourceType: 'module' }) 145 | }) 146 | t.end() 147 | }) 148 | 149 | test('walk supports plugin syntax', function (t) { 150 | var ast = acorn.parse( 151 | 'async function* a() { try { await import(xyz); } catch { for await (x of null) {} } yield import.meta.url }', 152 | { sourceType: 'module' } 153 | ) 154 | t.plan(2) 155 | walk.simple(ast, { 156 | ImportExpression: function () { 157 | t.pass('import()') 158 | }, 159 | MetaProperty: function () { 160 | t.pass('import.meta') 161 | } 162 | }) 163 | t.end() 164 | }) 165 | --------------------------------------------------------------------------------