[Pkg-javascript-commits] [acorn] 01/05: New upstream version 5.3.0+ds1
Julien Puydt
julien.puydt at laposte.net
Wed Jan 3 10:12:04 UTC 2018
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to annotated tag debian/5.3.0+ds1-1
in repository acorn.
commit af8adb1c367c823f9b9a4d0c502d5d703fed341a
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Wed Jan 3 10:38:37 2018 +0100
New upstream version 5.3.0+ds1
---
.gitignore | 3 +-
.travis.yml | 23 ++-
AUTHORS | 5 +
CHANGELOG.md | 22 +++
README.md | 27 +--
bin/acorn | 4 +
bin/run_test262.js | 27 +++
bin/test262.whitelist | 372 +++++++++++++++++++++++++++++++++++++++
package.json | 20 ++-
rollup/config.bin.js | 2 +-
src/.eslintrc | 4 +-
src/expression.js | 48 +++---
src/identifier.js | 2 +
src/index.js | 6 +-
src/lval.js | 66 +++----
src/parseutil.js | 17 +-
src/statement.js | 143 +++++++--------
src/tokenize.js | 38 ++--
src/walk/index.js | 5 +
test/tests-asyncawait.js | 22 +--
test/tests-harmony.js | 440 ++++++++++++++++++++++++++++++++++++++++++++---
test/tests.js | 179 ++++++++++++++++++-
22 files changed, 1252 insertions(+), 223 deletions(-)
diff --git a/.gitignore b/.gitignore
index 2fd9f03..429c4fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
+.DS_Store
node_modules
/.tern-port
/local
-/bin/acorn
+/bin/_acorn.js
/dist
diff --git a/.travis.yml b/.travis.yml
index deb2a57..441d5fc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,18 @@
language: node_js
sudo: false
-node_js:
- - '0.12'
- - '4'
- - '5'
- - '6'
- - '7'
- - '8'
+matrix:
+ include:
+ - node_js: '0.12'
+ - node_js: '4'
+ - node_js: '5'
+ - node_js: '6'
+ - node_js: '7'
+ - node_js: '8'
+ - node_js: '8'
+ env: TEST_SUITE=test262
+script: >
+ if [ "$TEST_SUITE" != "test262" ]; then
+ npm test
+ else
+ npm run test:test262
+ fi
diff --git a/AUTHORS b/AUTHORS
index 78437f6..bdbfea2 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,5 +1,7 @@
List of Acorn contributors. Updated before every release.
+Adrian Heine
+Adrian Heine né Lang
Adrian Rakovsky
Alistair Braidwood
Amila Welihinda
@@ -11,11 +13,13 @@ Artem Govorov
Bradley Heinz
Brandon Mills
Charles Hughes
+Charmander
Conrad Irwin
Daniel Tschinder
David Bonnet
Domenico Matteo
ehmicky
+Felix Maier
Forbes Lindesay
Gilad Peleg
impinball
@@ -34,6 +38,7 @@ Keheliya Gallaba
Kevin Irish
Kevin Kwok
krator
+laosb
Marek
Marijn Haverbeke
Martin Carlberg
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3003a04..fff956a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,25 @@
+## 5.3.0 (2017-12-28)
+
+### Bug fixes
+
+Fix parsing of floating point literals with leading zeroes in loose mode.
+
+Allow duplicate property names in object patterns.
+
+Don't allow static class methods named `prototype`.
+
+Disallow async functions directly under `if` or `else`.
+
+Parse right-hand-side of `for`/`of` as an assignment expression.
+
+Stricter parsing of `for`/`in`.
+
+Don't allow unicode escapes in contextual keywords.
+
+### New features
+
+Parsing class members was factored into smaller methods to allow plugins to hook into it.
+
## 5.2.1 (2017-10-30)
### Bug fixes
diff --git a/README.md b/README.md
index ab2c12e..8855fa7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Acorn
-[![Build Status](https://travis-ci.org/ternjs/acorn.svg?branch=master)](https://travis-ci.org/ternjs/acorn)
+[![Build Status](https://travis-ci.org/acornjs/acorn.svg?branch=master)](https://travis-ci.org/acornjs/acorn)
[![NPM version](https://img.shields.io/npm/v/acorn.svg)](https://www.npmjs.com/package/acorn)
[![CDNJS](https://img.shields.io/cdnjs/v/acorn.svg)](https://cdnjs.com/libraries/acorn)
[Author funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?force)](https://marijnhaverbeke.nl/fund/)
@@ -10,13 +10,13 @@ A tiny, fast JavaScript parser, written completely in JavaScript.
## Community
Acorn is open source software released under an
-[MIT license](https://github.com/ternjs/acorn/blob/master/LICENSE).
+[MIT license](https://github.com/acornjs/acorn/blob/master/LICENSE).
You are welcome to
-[report bugs](https://github.com/ternjs/acorn/issues) or create pull
-requests on [github](https://github.com/ternjs/acorn). For questions
+[report bugs](https://github.com/acornjs/acorn/issues) or create pull
+requests on [github](https://github.com/acornjs/acorn). For questions
and discussion, please use the
-[Tern discussion forum](https://discuss.ternjs.net).
+[Tern discussion forum](https://discuss.acornjs.net).
## Installation
@@ -31,7 +31,7 @@ npm install acorn
Alternately, download the source.
```sh
-git clone https://github.com/ternjs/acorn.git
+git clone https://github.com/acornjs/acorn.git
```
## Components
@@ -443,10 +443,13 @@ looseParser.extend("readToken", function(nextMethod) {
### Existing plugins
- [`acorn-jsx`](https://github.com/RReverser/acorn-jsx): Parse [Facebook JSX syntax extensions](https://github.com/facebook/jsx)
- - [`acorn-es7-plugin`](https://github.com/MatAtBread/acorn-es7-plugin/): Parse [async/await syntax proposal](https://github.com/tc39/ecmascript-asyncawait)
- - [`acorn-object-spread`](https://github.com/UXtemple/acorn-object-spread): Parse [object spread syntax proposal](https://github.com/sebmarkbage/ecmascript-rest-spread)
- - [`acorn-es7`](https://www.npmjs.com/package/acorn-es7): Parse [decorator syntax proposal](https://github.com/wycats/javascript-decorators)
- - [`acorn-objj`](https://www.npmjs.com/package/acorn-objj): [Objective-J](http://www.cappuccino-project.org/learn/objective-j.html) language parser built as Acorn plugin
- - [`acorn-object-rest-spread`](https://github.com/victor-homyakov/acorn-object-rest-spread) Parse [Object Rest/Spread Properties proposal](https://github.com/tc39/proposal-object-rest-spread), works with latest Acorn version (5.0.3)
- - [`acorn-static-class-property-initializer`](https://github.com/victor-homyakov/acorn-static-class-property-initializer) Partial support for static class properties from [ES Class Fields & Static Properties Proposal](https://github.com/tc39/proposal-class-public-fields) to support static property initializers in [React components written as ES6+ classes](https://babeljs.io/blog/2015/06/07/react-on-es6-plus)
+ - [`acorn-objj`](https://github.com/cappuccino/acorn-objj): [Objective-J](http://www.cappuccino-project.org/learn/objective-j.html) language parser built as Acorn plugin
+ Plugins for ECMAScript proposals:
+
+ - [`acorn-object-rest-spread`](https://github.com/victor-homyakov/acorn-object-rest-spread): Parse [Object Rest/Spread Properties proposal](https://github.com/tc39/proposal-object-rest-spread)
+ - [`acorn5-object-spread`](https://github.com/adrianheine/acorn5-object-spread): Parse [Object Rest/Spread Properties proposal](https://github.com/tc39/proposal-object-rest-spread)
+ - [`acorn-es7`](https://github.com/angelozerr/acorn-es7): Parse [decorator syntax proposal](https://github.com/wycats/javascript-decorators)
+ - [`acorn-static-class-property-initializer`](https://github.com/victor-homyakov/acorn-static-class-property-initializer): Partial support for static class properties from [ES Class Fields & Static Properties Proposal](https://github.com/tc39/proposal-class-public-fields) to support static property initializers in [React components written as ES6+ classes](https://babeljs.io/blog/2015/06/07/react-on-es6-plus)
+ - [`acorn-dynamic-import`](https://github.com/kesne/acorn-dynamic-import): Parse [import() proposal](https://github.com/tc39/proposal-dynamic-import)
+ - [`acorn-async-iteration`](https://github.com/adrianheine/acorn-async-iteration): Parse [async iteration proposal](https://github.com/tc39/proposal-async-iteration)
diff --git a/bin/acorn b/bin/acorn
new file mode 100755
index 0000000..03888d0
--- /dev/null
+++ b/bin/acorn
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+'use strict';
+
+require('./_acorn.js');
diff --git a/bin/run_test262.js b/bin/run_test262.js
new file mode 100644
index 0000000..b0e4e8f
--- /dev/null
+++ b/bin/run_test262.js
@@ -0,0 +1,27 @@
+const fs = require("fs")
+const path = require("path")
+const run = require("test262-parser-runner")
+const parse = require("..").parse
+
+const unsupportedFeatures = [
+ "async-iteration",
+ "BigInt",
+ "class-fields",
+ "class-fields-private",
+ "class-fields-public",
+ "object-rest",
+ "object-spread",
+ "optional-catch-binding",
+ "regexp-lookbehind",
+ "regexp-named-groups",
+ "regexp-unicode-property-escapes"
+];
+
+run(
+ (content, {sourceType}) => parse(content, {sourceType, ecmaVersion: 9}),
+ {
+ testsDirectory: path.dirname(require.resolve("test262/package.json")),
+ skip: test => (test.attrs.features && unsupportedFeatures.some(f => test.attrs.features.includes(f))),
+ whitelist: fs.readFileSync("./bin/test262.whitelist", "utf8").split("\n").filter(v => v)
+ }
+)
diff --git a/bin/test262.whitelist b/bin/test262.whitelist
new file mode 100644
index 0000000..4524b3b
--- /dev/null
+++ b/bin/test262.whitelist
@@ -0,0 +1,372 @@
+annexB/language/function-code/block-decl-func-no-skip-try.js (default)
+annexB/language/function-code/block-decl-func-skip-early-err-block.js (default)
+annexB/language/function-code/block-decl-func-skip-early-err.js (default)
+annexB/language/function-code/block-decl-func-skip-early-err-switch.js (default)
+annexB/language/function-code/block-decl-func-skip-early-err-try.js (default)
+annexB/language/function-code/if-decl-else-decl-a-func-no-skip-try.js (default)
+annexB/language/function-code/if-decl-else-decl-a-func-skip-early-err-block.js (default)
+annexB/language/function-code/if-decl-else-decl-a-func-skip-early-err.js (default)
+annexB/language/function-code/if-decl-else-decl-a-func-skip-early-err-switch.js (default)
+annexB/language/function-code/if-decl-else-decl-a-func-skip-early-err-try.js (default)
+annexB/language/function-code/if-decl-else-decl-b-func-no-skip-try.js (default)
+annexB/language/function-code/if-decl-else-decl-b-func-skip-early-err-block.js (default)
+annexB/language/function-code/if-decl-else-decl-b-func-skip-early-err.js (default)
+annexB/language/function-code/if-decl-else-decl-b-func-skip-early-err-switch.js (default)
+annexB/language/function-code/if-decl-else-decl-b-func-skip-early-err-try.js (default)
+annexB/language/function-code/if-decl-else-stmt-func-no-skip-try.js (default)
+annexB/language/function-code/if-decl-else-stmt-func-skip-early-err-block.js (default)
+annexB/language/function-code/if-decl-else-stmt-func-skip-early-err.js (default)
+annexB/language/function-code/if-decl-else-stmt-func-skip-early-err-switch.js (default)
+annexB/language/function-code/if-decl-else-stmt-func-skip-early-err-try.js (default)
+annexB/language/function-code/if-decl-no-else-func-no-skip-try.js (default)
+annexB/language/function-code/if-decl-no-else-func-skip-early-err-block.js (default)
+annexB/language/function-code/if-decl-no-else-func-skip-early-err.js (default)
+annexB/language/function-code/if-decl-no-else-func-skip-early-err-switch.js (default)
+annexB/language/function-code/if-decl-no-else-func-skip-early-err-try.js (default)
+annexB/language/function-code/if-stmt-else-decl-func-no-skip-try.js (default)
+annexB/language/function-code/if-stmt-else-decl-func-skip-early-err-block.js (default)
+annexB/language/function-code/if-stmt-else-decl-func-skip-early-err.js (default)
+annexB/language/function-code/if-stmt-else-decl-func-skip-early-err-switch.js (default)
+annexB/language/function-code/if-stmt-else-decl-func-skip-early-err-try.js (default)
+annexB/language/function-code/switch-case-func-no-skip-try.js (default)
+annexB/language/function-code/switch-case-func-skip-early-err-block.js (default)
+annexB/language/function-code/switch-case-func-skip-early-err.js (default)
+annexB/language/function-code/switch-case-func-skip-early-err-switch.js (default)
+annexB/language/function-code/switch-case-func-skip-early-err-try.js (default)
+annexB/language/function-code/switch-dflt-func-no-skip-try.js (default)
+annexB/language/function-code/switch-dflt-func-skip-early-err-block.js (default)
+annexB/language/function-code/switch-dflt-func-skip-early-err.js (default)
+annexB/language/function-code/switch-dflt-func-skip-early-err-switch.js (default)
+annexB/language/function-code/switch-dflt-func-skip-early-err-try.js (default)
+annexB/language/global-code/block-decl-global-no-skip-try.js (default)
+annexB/language/global-code/block-decl-global-skip-early-err-block.js (default)
+annexB/language/global-code/block-decl-global-skip-early-err.js (default)
+annexB/language/global-code/block-decl-global-skip-early-err-switch.js (default)
+annexB/language/global-code/block-decl-global-skip-early-err-try.js (default)
+annexB/language/global-code/if-decl-else-decl-a-global-no-skip-try.js (default)
+annexB/language/global-code/if-decl-else-decl-a-global-skip-early-err-block.js (default)
+annexB/language/global-code/if-decl-else-decl-a-global-skip-early-err.js (default)
+annexB/language/global-code/if-decl-else-decl-a-global-skip-early-err-switch.js (default)
+annexB/language/global-code/if-decl-else-decl-a-global-skip-early-err-try.js (default)
+annexB/language/global-code/if-decl-else-decl-b-global-no-skip-try.js (default)
+annexB/language/global-code/if-decl-else-decl-b-global-skip-early-err-block.js (default)
+annexB/language/global-code/if-decl-else-decl-b-global-skip-early-err.js (default)
+annexB/language/global-code/if-decl-else-decl-b-global-skip-early-err-switch.js (default)
+annexB/language/global-code/if-decl-else-decl-b-global-skip-early-err-try.js (default)
+annexB/language/global-code/if-decl-else-stmt-global-no-skip-try.js (default)
+annexB/language/global-code/if-decl-else-stmt-global-skip-early-err-block.js (default)
+annexB/language/global-code/if-decl-else-stmt-global-skip-early-err.js (default)
+annexB/language/global-code/if-decl-else-stmt-global-skip-early-err-switch.js (default)
+annexB/language/global-code/if-decl-else-stmt-global-skip-early-err-try.js (default)
+annexB/language/global-code/if-decl-no-else-global-no-skip-try.js (default)
+annexB/language/global-code/if-decl-no-else-global-skip-early-err-block.js (default)
+annexB/language/global-code/if-decl-no-else-global-skip-early-err.js (default)
+annexB/language/global-code/if-decl-no-else-global-skip-early-err-switch.js (default)
+annexB/language/global-code/if-decl-no-else-global-skip-early-err-try.js (default)
+annexB/language/global-code/if-stmt-else-decl-global-no-skip-try.js (default)
+annexB/language/global-code/if-stmt-else-decl-global-skip-early-err-block.js (default)
+annexB/language/global-code/if-stmt-else-decl-global-skip-early-err.js (default)
+annexB/language/global-code/if-stmt-else-decl-global-skip-early-err-switch.js (default)
+annexB/language/global-code/if-stmt-else-decl-global-skip-early-err-try.js (default)
+annexB/language/global-code/switch-case-global-no-skip-try.js (default)
+annexB/language/global-code/switch-case-global-skip-early-err-block.js (default)
+annexB/language/global-code/switch-case-global-skip-early-err.js (default)
+annexB/language/global-code/switch-case-global-skip-early-err-switch.js (default)
+annexB/language/global-code/switch-case-global-skip-early-err-try.js (default)
+annexB/language/global-code/switch-dflt-global-no-skip-try.js (default)
+annexB/language/global-code/switch-dflt-global-skip-early-err-block.js (default)
+annexB/language/global-code/switch-dflt-global-skip-early-err.js (default)
+annexB/language/global-code/switch-dflt-global-skip-early-err-switch.js (default)
+annexB/language/global-code/switch-dflt-global-skip-early-err-try.js (default)
+annexB/language/statements/try/catch-redeclared-for-in-var.js (default)
+annexB/language/statements/try/catch-redeclared-for-in-var.js (strict mode)
+annexB/language/statements/try/catch-redeclared-for-var.js (default)
+annexB/language/statements/try/catch-redeclared-for-var.js (strict mode)
+annexB/language/statements/try/catch-redeclared-var-statement-captured.js (default)
+annexB/language/statements/try/catch-redeclared-var-statement-captured.js (strict mode)
+annexB/language/statements/try/catch-redeclared-var-statement.js (default)
+annexB/language/statements/try/catch-redeclared-var-statement.js (strict mode)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/block-scope/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-const-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-const-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-let-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-let-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/block-scope/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/const-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/const-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/block-scope/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/block-scope/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/let-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/let-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/block-scope/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/expressions/async-arrow-function/early-errors-arrow-await-in-formals-default.js (default)
+language/expressions/async-arrow-function/early-errors-arrow-await-in-formals-default.js (strict mode)
+language/expressions/async-arrow-function/early-errors-arrow-body-contains-super-call.js (default)
+language/expressions/async-arrow-function/early-errors-arrow-body-contains-super-call.js (strict mode)
+language/expressions/async-arrow-function/early-errors-arrow-body-contains-super-property.js (default)
+language/expressions/async-arrow-function/early-errors-arrow-body-contains-super-property.js (strict mode)
+language/expressions/async-function/early-errors-expression-body-contains-super-call.js (default)
+language/expressions/async-function/early-errors-expression-body-contains-super-call.js (strict mode)
+language/expressions/async-function/early-errors-expression-body-contains-super-property.js (default)
+language/expressions/async-function/early-errors-expression-body-contains-super-property.js (strict mode)
+language/expressions/async-function/early-errors-expression-formals-contains-super-call.js (default)
+language/expressions/async-function/early-errors-expression-formals-contains-super-call.js (strict mode)
+language/expressions/async-function/early-errors-expression-formals-contains-super-property.js (default)
+language/expressions/async-function/early-errors-expression-formals-contains-super-property.js (strict mode)
+language/expressions/class/method-param-dflt-yield.js (default)
+language/expressions/class/static-method-param-dflt-yield.js (default)
+language/expressions/function/early-body-super-call.js (default)
+language/expressions/function/early-body-super-call.js (strict mode)
+language/expressions/function/early-body-super-prop.js (default)
+language/expressions/function/early-body-super-prop.js (strict mode)
+language/expressions/function/early-params-super-call.js (default)
+language/expressions/function/early-params-super-call.js (strict mode)
+language/expressions/function/early-params-super-prop.js (default)
+language/expressions/function/early-params-super-prop.js (strict mode)
+language/expressions/object/method-definition/early-errors-object-method-body-contains-super-call.js (default)
+language/expressions/object/method-definition/early-errors-object-method-body-contains-super-call.js (strict mode)
+language/expressions/object/method-definition/early-errors-object-method-duplicate-parameters.js (default)
+language/expressions/object/method-definition/early-errors-object-method-formals-contains-super-call.js (default)
+language/expressions/object/method-definition/early-errors-object-method-formals-contains-super-call.js (strict mode)
+language/expressions/object/method-definition/generator-super-call-body.js (default)
+language/expressions/object/method-definition/generator-super-call-body.js (strict mode)
+language/expressions/object/method-definition/generator-super-call-param.js (default)
+language/expressions/object/method-definition/generator-super-call-param.js (strict mode)
+language/expressions/object/prop-def-invalid-async-prefix.js (default)
+language/expressions/object/prop-def-invalid-async-prefix.js (strict mode)
+language/expressions/yield/in-iteration-stmt.js (default)
+language/expressions/yield/in-iteration-stmt.js (strict mode)
+language/expressions/yield/star-in-iteration-stmt.js (default)
+language/expressions/yield/star-in-iteration-stmt.js (strict mode)
+language/global-code/new.target-arrow.js (default)
+language/global-code/new.target-arrow.js (strict mode)
+language/global-code/super-call-arrow.js (default)
+language/global-code/super-call-arrow.js (strict mode)
+language/global-code/super-prop-arrow.js (default)
+language/global-code/super-prop-arrow.js (strict mode)
+language/literals/regexp/early-err-dup-flag.js (default)
+language/literals/regexp/early-err-dup-flag.js (strict mode)
+language/literals/regexp/early-err-flags-unicode-escape.js (default)
+language/literals/regexp/early-err-flags-unicode-escape.js (strict mode)
+language/literals/string/legacy-non-octal-escape-sequence-strict.js (strict mode)
+language/module-code/early-export-global.js (default)
+language/module-code/early-export-global.js (strict mode)
+language/module-code/early-export-unresolvable.js (default)
+language/module-code/early-export-unresolvable.js (strict mode)
+language/module-code/instn-resolve-empty-export.js (default)
+language/module-code/instn-resolve-empty-export.js (strict mode)
+language/module-code/instn-resolve-empty-import.js (default)
+language/module-code/instn-resolve-empty-import.js (strict mode)
+language/module-code/instn-resolve-err-reference.js (default)
+language/module-code/instn-resolve-err-reference.js (strict mode)
+language/module-code/instn-resolve-err-syntax.js (default)
+language/module-code/instn-resolve-err-syntax.js (strict mode)
+language/module-code/instn-resolve-order-depth.js (default)
+language/module-code/instn-resolve-order-depth.js (strict mode)
+language/module-code/instn-resolve-order-src.js (default)
+language/module-code/instn-resolve-order-src.js (strict mode)
+language/module-code/parse-err-hoist-lex-fun.js (default)
+language/module-code/parse-err-hoist-lex-fun.js (strict mode)
+language/module-code/parse-err-hoist-lex-gen.js (default)
+language/module-code/parse-err-hoist-lex-gen.js (strict mode)
+language/statements/async-function/early-errors-declaration-body-contains-super-call.js (default)
+language/statements/async-function/early-errors-declaration-body-contains-super-call.js (strict mode)
+language/statements/async-function/early-errors-declaration-body-contains-super-property.js (default)
+language/statements/async-function/early-errors-declaration-body-contains-super-property.js (strict mode)
+language/statements/async-function/early-errors-declaration-formals-contains-super-call.js (default)
+language/statements/async-function/early-errors-declaration-formals-contains-super-call.js (strict mode)
+language/statements/async-function/early-errors-declaration-formals-contains-super-property.js (default)
+language/statements/async-function/early-errors-declaration-formals-contains-super-property.js (strict mode)
+language/statements/class/definition/early-errors-class-method-arguments-in-formal-parameters.js (default)
+language/statements/class/definition/early-errors-class-method-body-contains-super-call.js (default)
+language/statements/class/definition/early-errors-class-method-body-contains-super-call.js (strict mode)
+language/statements/class/definition/early-errors-class-method-duplicate-parameters.js (default)
+language/statements/class/definition/early-errors-class-method-eval-in-formal-parameters.js (default)
+language/statements/class/definition/early-errors-class-method-formals-contains-super-call.js (default)
+language/statements/class/definition/early-errors-class-method-formals-contains-super-call.js (strict mode)
+language/statements/class/definition/methods-gen-yield-as-function-expression-binding-identifier.js (default)
+language/statements/class/definition/methods-gen-yield-as-identifier-in-nested-function.js (default)
+language/statements/class/method-param-yield.js (default)
+language/statements/class/static-method-param-yield.js (default)
+language/statements/class/strict-mode/with.js (default)
+language/statements/class/syntax/early-errors/class-body-has-direct-super-missing-class-heritage.js (default)
+language/statements/class/syntax/early-errors/class-body-has-direct-super-missing-class-heritage.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-method-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-method-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-special-method-generator-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-special-method-generator-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-special-method-get-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-special-method-get-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-special-method-set-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-special-method-set-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-static-method-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-static-method-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-static-method-get-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-static-method-get-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-body-static-method-set-contains-direct-super.js (default)
+language/statements/class/syntax/early-errors/class-body-static-method-set-contains-direct-super.js (strict mode)
+language/statements/class/syntax/early-errors/class-definition-evaluation-block-duplicate-binding.js (default)
+language/statements/class/syntax/early-errors/class-definition-evaluation-block-duplicate-binding.js (strict mode)
+language/statements/class/syntax/early-errors/class-definition-evaluation-scriptbody-duplicate-binding.js (default)
+language/statements/class/syntax/early-errors/class-definition-evaluation-scriptbody-duplicate-binding.js (strict mode)
+language/statements/const/syntax/const-declaring-let-split-across-two-lines.js (default)
+language/statements/do-while/labelled-fn-stmt.js (default)
+language/statements/for/head-let-bound-names-in-stmt.js (default)
+language/statements/for/head-let-bound-names-in-stmt.js (strict mode)
+language/statements/for-in/head-const-bound-names-in-stmt.js (default)
+language/statements/for-in/head-const-bound-names-in-stmt.js (strict mode)
+language/statements/for-in/head-const-bound-names-let.js (default)
+language/statements/for-in/head-let-bound-names-in-stmt.js (default)
+language/statements/for-in/head-let-bound-names-in-stmt.js (strict mode)
+language/statements/for-in/head-let-bound-names-let.js (default)
+language/statements/for-in/labelled-fn-stmt-const.js (default)
+language/statements/for-in/labelled-fn-stmt-let.js (default)
+language/statements/for-in/labelled-fn-stmt-lhs.js (default)
+language/statements/for-in/labelled-fn-stmt-var.js (default)
+language/statements/for-in/let-block-with-newline.js (default)
+language/statements/for-in/let-identifier-with-newline.js (default)
+language/statements/for/labelled-fn-stmt-expr.js (default)
+language/statements/for/labelled-fn-stmt-let.js (default)
+language/statements/for/labelled-fn-stmt-var.js (default)
+language/statements/for/let-block-with-newline.js (default)
+language/statements/for/let-identifier-with-newline.js (default)
+language/statements/for-of/head-const-bound-names-in-stmt.js (default)
+language/statements/for-of/head-const-bound-names-in-stmt.js (strict mode)
+language/statements/for-of/head-const-bound-names-let.js (default)
+language/statements/for-of/head-let-bound-names-in-stmt.js (default)
+language/statements/for-of/head-let-bound-names-in-stmt.js (strict mode)
+language/statements/for-of/head-let-bound-names-let.js (default)
+language/statements/for-of/labelled-fn-stmt-const.js (default)
+language/statements/for-of/labelled-fn-stmt-let.js (default)
+language/statements/for-of/labelled-fn-stmt-lhs.js (default)
+language/statements/for-of/labelled-fn-stmt-var.js (default)
+language/statements/for-of/let-block-with-newline.js (default)
+language/statements/for-of/let-identifier-with-newline.js (default)
+language/statements/function/early-body-super-call.js (default)
+language/statements/function/early-body-super-call.js (strict mode)
+language/statements/function/early-body-super-prop.js (default)
+language/statements/function/early-body-super-prop.js (strict mode)
+language/statements/function/early-params-super-call.js (default)
+language/statements/function/early-params-super-call.js (strict mode)
+language/statements/function/early-params-super-prop.js (default)
+language/statements/function/early-params-super-prop.js (strict mode)
+language/statements/if/if-gen-else-gen.js (default)
+language/statements/if/if-gen-else-stmt.js (default)
+language/statements/if/if-gen-no-else.js (default)
+language/statements/if/if-stmt-else-gen.js (default)
+language/statements/if/labelled-fn-stmt-first.js (default)
+language/statements/if/labelled-fn-stmt-lone.js (default)
+language/statements/if/labelled-fn-stmt-second.js (default)
+language/statements/if/let-block-with-newline.js (default)
+language/statements/if/let-identifier-with-newline.js (default)
+language/statements/labeled/decl-async-function.js (default)
+language/statements/labeled/let-block-with-newline.js (default)
+language/statements/labeled/let-identifier-with-newline.js (default)
+language/statements/let/syntax/identifier-let-disallowed-as-boundname.js (default)
+language/statements/let/syntax/let-let-declaration-split-across-two-lines.js (default)
+language/statements/let/syntax/let-let-declaration-with-initializer-split-across-two-lines.js (default)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/statements/switch/syntax/redeclaration/async-function-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-const-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-const-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-let-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-let-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/statements/switch/syntax/redeclaration/class-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/const-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/const-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/statements/switch/syntax/redeclaration/function-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-var-declaration.js (default)
+language/statements/switch/syntax/redeclaration/generator-declaration-attempt-to-redeclare-with-var-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/let-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/let-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-async-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-async-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-class-declaration.js (default)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-class-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-function-declaration.js (default)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-function-declaration.js (strict mode)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-generator-declaration.js (default)
+language/statements/switch/syntax/redeclaration/var-declaration-attempt-to-redeclare-with-generator-declaration.js (strict mode)
+language/statements/while/labelled-fn-stmt.js (default)
+language/statements/while/let-block-with-newline.js (default)
+language/statements/while/let-identifier-with-newline.js (default)
+language/statements/with/labelled-fn-stmt.js (default)
+language/statements/with/let-block-with-newline.js (default)
+language/statements/with/let-identifier-with-newline.js (default)
+language/white-space/mongolian-vowel-separator.js (default)
+language/white-space/mongolian-vowel-separator.js (strict mode)
diff --git a/package.json b/package.json
index 56c63a4..4fe2abd 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,10 @@
{
"name": "acorn",
"description": "ECMAScript parser",
- "homepage": "https://github.com/ternjs/acorn",
+ "homepage": "https://github.com/acornjs/acorn",
"main": "dist/acorn.js",
"module": "dist/acorn.es.js",
- "version": "5.2.1",
+ "version": "5.3.0",
"engines": {
"node": ">=0.4.0"
},
@@ -22,13 +22,14 @@
],
"repository": {
"type": "git",
- "url": "https://github.com/ternjs/acorn.git"
+ "url": "https://github.com/acornjs/acorn.git"
},
"license": "MIT",
"scripts": {
"prepare": "npm test",
"test": "node test/run.js && node test/lint.js",
"pretest": "npm run build:main && npm run build:loose",
+ "test:test262": "node bin/run_test262.js",
"build": "npm run build:main && npm run build:walk && npm run build:loose && npm run build:bin",
"build:main": "rollup -c rollup/config.main.js",
"build:walk": "rollup -c rollup/config.walk.js",
@@ -40,13 +41,16 @@
"acorn": "./bin/acorn"
},
"devDependencies": {
- "eslint": "^3.18.0",
- "eslint-config-standard": "^7.1.0",
+ "eslint": "^4.10.0",
+ "eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.2.0",
+ "eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.5.0",
- "eslint-plugin-standard": "^2.1.1",
- "rollup": "^0.43.0",
- "rollup-plugin-buble": "^0.15.0",
+ "eslint-plugin-standard": "^3.0.1",
+ "rollup": "^0.45.0",
+ "rollup-plugin-buble": "^0.16.0",
+ "test262-parser-runner": "^0.2.0",
+ "test262": "git+https://github.com/tc39/test262.git#51553973738063f457e248f7f1e643c561c8a64c",
"unicode-9.0.0": "^0.7.0"
}
}
diff --git a/rollup/config.bin.js b/rollup/config.bin.js
index 3726606..3b1c899 100644
--- a/rollup/config.bin.js
+++ b/rollup/config.bin.js
@@ -2,7 +2,7 @@ import buble from 'rollup-plugin-buble'
export default {
entry: 'src/bin/acorn.js',
- dest: 'bin/acorn',
+ dest: 'bin/_acorn.js',
format: 'cjs',
banner: '#!/usr/bin/env node',
external: [ 'fs', 'path', 'acorn' ],
diff --git a/src/.eslintrc b/src/.eslintrc
index 5549678..e636ee7 100644
--- a/src/.eslintrc
+++ b/src/.eslintrc
@@ -8,7 +8,7 @@
"rules": {
"curly": "off",
"eqeqeq": "off",
- "indent": ["error", 2, { "SwitchCase": 0, "VariableDeclarator": 2 }],
+ "indent": ["error", 2, { "SwitchCase": 0, "VariableDeclarator": 2, "CallExpression": { arguments: "off" } }],
"new-parens": "off",
"no-case-declarations": "off",
"no-cond-assign": "off",
@@ -30,4 +30,4 @@
"plugins": [
"import"
]
-}
\ No newline at end of file
+}
diff --git a/src/expression.js b/src/expression.js
index 033d13c..29f39f4 100644
--- a/src/expression.js
+++ b/src/expression.js
@@ -28,7 +28,7 @@ const pp = Parser.prototype
// either with each other or with an init property — and in
// strict mode, init properties are also not allowed to be repeated.
-pp.checkPropClash = function(prop, propHash) {
+pp.checkPropClash = function(prop, propHash, refDestructuringErrors) {
if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
return
let {key} = prop, name
@@ -40,7 +40,11 @@ pp.checkPropClash = function(prop, propHash) {
let {kind} = prop
if (this.options.ecmaVersion >= 6) {
if (name === "__proto__" && kind === "init") {
- if (propHash.proto) this.raiseRecoverable(key.start, "Redefinition of __proto__ property")
+ if (propHash.proto) {
+ if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) refDestructuringErrors.doubleProto = key.start
+ // Backwards-compat kludge. Can be removed in version 6.0
+ else this.raiseRecoverable(key.start, "Redefinition of __proto__ property")
+ }
propHash.proto = true
}
return
@@ -115,11 +119,10 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
let left = this.parseMaybeConditional(noIn, refDestructuringErrors)
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc)
if (this.type.isAssign) {
- this.checkPatternErrors(refDestructuringErrors, true)
- if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors)
let node = this.startNodeAt(startPos, startLoc)
node.operator = this.value
- node.left = this.type === tt.eq ? this.toAssignable(left) : left
+ node.left = this.type === tt.eq ? this.toAssignable(left, false, refDestructuringErrors) : left
+ if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors)
refDestructuringErrors.shorthandAssign = -1 // reset because shorthand default was used correctly
this.checkLVal(left)
this.next()
@@ -246,7 +249,7 @@ pp.parseExprSubscripts = function(refDestructuringErrors) {
pp.parseSubscripts = function(base, startPos, startLoc, noCalls) {
let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
- this.lastTokEnd == base.end && !this.canInsertSemicolon()
+ this.lastTokEnd == base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async"
for (let computed;;) {
if ((computed = this.eat(tt.bracketL)) || this.eat(tt.dot)) {
let node = this.startNodeAt(startPos, startLoc)
@@ -314,14 +317,14 @@ pp.parseExprAtom = function(refDestructuringErrors) {
return this.finishNode(node, "ThisExpression")
case tt.name:
- let startPos = this.start, startLoc = this.startLoc
+ let startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc
let id = this.parseIdent(this.type !== tt.name)
- if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(tt._function))
+ if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(tt._function))
return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true)
if (canBeArrow && !this.canInsertSemicolon()) {
if (this.eat(tt.arrow))
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false)
- if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === tt.name) {
+ if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === tt.name && !containsEsc) {
id = this.parseIdent()
if (this.canInsertSemicolon() || !this.eat(tt.arrow))
this.unexpected()
@@ -406,7 +409,7 @@ pp.parseParenAndDistinguishExpression = function(canBeArrow) {
let innerStartPos = this.start, innerStartLoc = this.startLoc
let exprList = [], first = true, lastIsComma = false
- let refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart
+ let refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart
this.yieldPos = 0
this.awaitPos = 0
while (this.type !== tt.parenR) {
@@ -420,9 +423,6 @@ pp.parseParenAndDistinguishExpression = function(canBeArrow) {
if (this.type === tt.comma) this.raise(this.start, "Comma is not permitted after the rest element")
break
} else {
- if (this.type === tt.parenL && !innerParenStart) {
- innerParenStart = this.start
- }
exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem))
}
}
@@ -432,7 +432,6 @@ pp.parseParenAndDistinguishExpression = function(canBeArrow) {
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
this.checkPatternErrors(refDestructuringErrors, false)
this.checkYieldAwaitInDefaultParams()
- if (innerParenStart) this.unexpected(innerParenStart)
this.yieldPos = oldYieldPos
this.awaitPos = oldAwaitPos
return this.parseParenArrowList(startPos, startLoc, exprList)
@@ -485,8 +484,9 @@ pp.parseNew = function() {
let meta = this.parseIdent(true)
if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
node.meta = meta
+ let containsEsc = this.containsEsc
node.property = this.parseIdent(true)
- if (node.property.name !== "target")
+ if (node.property.name !== "target" || containsEsc)
this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target")
if (!this.inFunction)
this.raiseRecoverable(node.start, "new.target can only be used in functions")
@@ -557,7 +557,7 @@ pp.parseObj = function(isPattern, refDestructuringErrors) {
} else first = false
const prop = this.parseProperty(isPattern, refDestructuringErrors)
- this.checkPropClash(prop, propHash)
+ if (!isPattern) this.checkPropClash(prop, propHash, refDestructuringErrors)
node.properties.push(prop)
}
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
@@ -575,18 +575,19 @@ pp.parseProperty = function(isPattern, refDestructuringErrors) {
if (!isPattern)
isGenerator = this.eat(tt.star)
}
+ let containsEsc = this.containsEsc
this.parsePropertyName(prop)
- if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
+ if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
isAsync = true
this.parsePropertyName(prop, refDestructuringErrors)
} else {
isAsync = false
}
- this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors)
+ this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc)
return this.finishNode(prop, "Property")
}
-pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
+pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
if ((isGenerator || isAsync) && this.type === tt.colon)
this.unexpected()
@@ -598,7 +599,7 @@ pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos
prop.kind = "init"
prop.method = true
prop.value = this.parseMethod(isGenerator, isAsync)
- } else if (!isPattern &&
+ } else if (!isPattern && !containsEsc &&
this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.type != tt.comma && this.type != tt.braceR)) {
@@ -816,8 +817,11 @@ pp.checkUnreserved = function({start, end, name}) {
if (this.options.ecmaVersion < 6 &&
this.input.slice(start, end).indexOf("\\") != -1) return
const re = this.strict ? this.reservedWordsStrict : this.reservedWords
- if (re.test(name))
+ if (re.test(name)) {
+ if (!this.inAsync && name === "await")
+ this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function")
this.raiseRecoverable(start, `The keyword '${name}' is reserved`)
+ }
}
// Parse the next token as an identifier. If `liberal` is true (used
@@ -832,7 +836,7 @@ pp.parseIdent = function(liberal, isBinding) {
} else if (this.type.keyword) {
node.name = this.type.keyword
- // To fix https://github.com/ternjs/acorn/issues/575
+ // To fix https://github.com/acornjs/acorn/issues/575
// `class` and `function` keywords push new context into this.context.
// But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
// If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
diff --git a/src/identifier.js b/src/identifier.js
index fa5ded6..3d19f63 100644
--- a/src/identifier.js
+++ b/src/identifier.js
@@ -17,6 +17,8 @@ export const keywords = {
6: ecma5AndLessKeywords + " const class extends export import super"
}
+export const keywordRelationalOperator = /^in(stanceof)?$/
+
// ## Character categories
// Big ugly regular expressions that match characters in the
diff --git a/src/index.js b/src/index.js
index d196b2a..781aa6e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,11 +6,11 @@
// Git repositories for Acorn are available at
//
// http://marijnhaverbeke.nl/git/acorn
-// https://github.com/ternjs/acorn.git
+// https://github.com/acornjs/acorn.git
//
// Please use the [github bug tracker][ghbt] to report issues.
//
-// [ghbt]: https://github.com/ternjs/acorn/issues
+// [ghbt]: https://github.com/acornjs/acorn/issues
//
// This file defines the main parser interface. The library also comes
// with a [error-tolerant parser][dammit] and an
@@ -37,7 +37,7 @@ export {isIdentifierChar, isIdentifierStart} from "./identifier"
export {Token} from "./tokenize"
export {isNewLine, lineBreak, lineBreakG, nonASCIIwhitespace} from "./whitespace"
-export const version = "5.2.1"
+export const version = "5.3.0"
// The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and
diff --git a/src/lval.js b/src/lval.js
index 1c47574..c5da84a 100644
--- a/src/lval.js
+++ b/src/lval.js
@@ -7,7 +7,7 @@ const pp = Parser.prototype
// Convert existing expression atom to assignable pattern
// if possible.
-pp.toAssignable = function(node, isBinding) {
+pp.toAssignable = function(node, isBinding, refDestructuringErrors) {
if (this.options.ecmaVersion >= 6 && node) {
switch (node.type) {
case "Identifier":
@@ -17,31 +17,41 @@ pp.toAssignable = function(node, isBinding) {
case "ObjectPattern":
case "ArrayPattern":
+ case "RestElement":
break
case "ObjectExpression":
node.type = "ObjectPattern"
- for (let prop of node.properties) {
- if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter")
- this.toAssignable(prop.value, isBinding)
- }
+ if (refDestructuringErrors) this.checkPatternErrors(refDestructuringErrors, true)
+ for (let prop of node.properties)
+ this.toAssignable(prop, isBinding)
+ break
+
+ case "Property":
+ // AssignmentProperty has type == "Property"
+ if (node.kind !== "init") this.raise(node.key.start, "Object pattern can't contain getter or setter")
+ this.toAssignable(node.value, isBinding)
break
case "ArrayExpression":
node.type = "ArrayPattern"
+ if (refDestructuringErrors) this.checkPatternErrors(refDestructuringErrors, true)
this.toAssignableList(node.elements, isBinding)
break
+ case "SpreadElement":
+ node.type = "RestElement"
+ this.toAssignable(node.argument, isBinding)
+ if (node.argument.type === "AssignmentPattern")
+ this.raise(node.argument.start, "Rest elements cannot have a default value")
+ break
+
case "AssignmentExpression":
- if (node.operator === "=") {
- node.type = "AssignmentPattern"
- delete node.operator
- this.toAssignable(node.left, isBinding)
- // falls through to AssignmentPattern
- } else {
- this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
- break
- }
+ if (node.operator !== "=") this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
+ node.type = "AssignmentPattern"
+ delete node.operator
+ this.toAssignable(node.left, isBinding)
+ // falls through to AssignmentPattern
case "AssignmentPattern":
break
@@ -56,7 +66,7 @@ pp.toAssignable = function(node, isBinding) {
default:
this.raise(node.start, "Assigning to rvalue")
}
- }
+ } else if (refDestructuringErrors) this.checkPatternErrors(refDestructuringErrors, true)
return node
}
@@ -64,24 +74,15 @@ pp.toAssignable = function(node, isBinding) {
pp.toAssignableList = function(exprList, isBinding) {
let end = exprList.length
+ for (let i = 0; i < end; i++) {
+ let elt = exprList[i]
+ if (elt) this.toAssignable(elt, isBinding)
+ }
if (end) {
let last = exprList[end - 1]
- if (last && last.type == "RestElement") {
- --end
- } else if (last && last.type == "SpreadElement") {
- last.type = "RestElement"
- let arg = last.argument
- this.toAssignable(arg, isBinding)
- --end
- }
-
if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
this.unexpected(last.argument.start)
}
- for (let i = 0; i < end; i++) {
- let elt = exprList[i]
- if (elt) this.toAssignable(elt, isBinding)
- }
return exprList
}
@@ -198,12 +199,17 @@ pp.checkLVal = function(expr, bindingType, checkClashes) {
break
case "MemberExpression":
- if (bindingType) this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression")
+ if (bindingType) this.raiseRecoverable(expr.start, "Binding member expression")
break
case "ObjectPattern":
for (let prop of expr.properties)
- this.checkLVal(prop.value, bindingType, checkClashes)
+ this.checkLVal(prop, bindingType, checkClashes)
+ break
+
+ case "Property":
+ // AssignmentProperty has type == "Property"
+ this.checkLVal(expr.value, bindingType, checkClashes)
break
case "ArrayPattern":
diff --git a/src/parseutil.js b/src/parseutil.js
index 5eda52f..e173637 100644
--- a/src/parseutil.js
+++ b/src/parseutil.js
@@ -33,13 +33,15 @@ pp.eat = function(type) {
// Tests whether parsed token is a contextual keyword.
pp.isContextual = function(name) {
- return this.type === tt.name && this.value === name
+ return this.type === tt.name && this.value === name && !this.containsEsc
}
// Consumes contextual keyword if possible.
pp.eatContextual = function(name) {
- return this.value === name && this.eat(tt.name)
+ if (!this.isContextual(name)) return false
+ this.next()
+ return true
}
// Asserts that following token is given contextual keyword.
@@ -99,6 +101,7 @@ export function DestructuringErrors() {
this.trailingComma =
this.parenthesizedAssign =
this.parenthesizedBind =
+ this.doubleProto =
-1
}
@@ -111,9 +114,13 @@ pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
}
pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
- let pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1
- if (!andThrow) return pos >= 0
- if (pos > -1) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns")
+ if (!refDestructuringErrors) return false
+ let {shorthandAssign, doubleProto} = refDestructuringErrors
+ if (!andThrow) return shorthandAssign >= 0 || doubleProto >= 0
+ if (shorthandAssign >= 0)
+ this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns")
+ if (doubleProto >= 0)
+ this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property")
}
pp.checkYieldAwaitInDefaultParams = function() {
diff --git a/src/statement.js b/src/statement.js
index 5d6cd1d..db2fb8b 100644
--- a/src/statement.js
+++ b/src/statement.js
@@ -1,7 +1,7 @@
import {types as tt} from "./tokentype"
import {Parser} from "./state"
import {lineBreak, skipWhiteSpace} from "./whitespace"
-import {isIdentifierStart, isIdentifierChar} from "./identifier"
+import {isIdentifierStart, isIdentifierChar, keywordRelationalOperator} from "./identifier"
import {has} from "./util"
import {DestructuringErrors} from "./parseutil"
@@ -32,7 +32,7 @@ pp.parseTopLevel = function(node) {
const loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"}
pp.isLet = function() {
- if (this.type !== tt.name || this.options.ecmaVersion < 6 || this.value != "let") return false
+ if (this.options.ecmaVersion < 6 || !this.isContextual("let")) return false
skipWhiteSpace.lastIndex = this.pos
let skip = skipWhiteSpace.exec(this.input)
let next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next)
@@ -41,7 +41,7 @@ pp.isLet = function() {
let pos = next + 1
while (isIdentifierChar(this.input.charCodeAt(pos), true)) ++pos
let ident = this.input.slice(next, pos)
- if (!this.isKeyword(ident)) return true
+ if (!keywordRelationalOperator.test(ident)) return true
}
return false
}
@@ -50,7 +50,7 @@ pp.isLet = function() {
// - 'async /*foo*/ function' is OK.
// - 'async /*\n*/ function' is invalid.
pp.isAsyncFunction = function() {
- if (this.type !== tt.name || this.options.ecmaVersion < 8 || this.value != "async")
+ if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
return false
skipWhiteSpace.lastIndex = this.pos
@@ -120,7 +120,8 @@ pp.parseStatement = function(declaration, topLevel, exports) {
// next token is a colon and the expression was a simple
// Identifier node, we switch to interpreting it as a label.
default:
- if (this.isAsyncFunction() && declaration) {
+ if (this.isAsyncFunction()) {
+ if (!declaration) this.unexpected()
this.next()
return this.parseFunctionStatement(node, true)
}
@@ -204,9 +205,8 @@ pp.parseForStatement = function(node) {
let refDestructuringErrors = new DestructuringErrors
let init = this.parseExpression(true, refDestructuringErrors)
if (this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
- this.toAssignable(init)
+ this.toAssignable(init, false, refDestructuringErrors)
this.checkLVal(init)
- this.checkPatternErrors(refDestructuringErrors, true)
return this.parseForIn(node, init)
} else {
this.checkExpressionErrors(refDestructuringErrors, true)
@@ -219,16 +219,12 @@ pp.parseFunctionStatement = function(node, isAsync) {
return this.parseFunction(node, true, false, isAsync)
}
-pp.isFunction = function() {
- return this.type === tt._function || this.isAsyncFunction()
-}
-
pp.parseIfStatement = function(node) {
this.next()
node.test = this.parseParenExpression()
// allow function declarations in branches, but only in non-strict mode
- node.consequent = this.parseStatement(!this.strict && this.isFunction())
- node.alternate = this.eat(tt._else) ? this.parseStatement(!this.strict && this.isFunction()) : null
+ node.consequent = this.parseStatement(!this.strict && this.type == tt._function)
+ node.alternate = this.eat(tt._else) ? this.parseStatement(!this.strict && this.type == tt._function) : null
return this.finishNode(node, "IfStatement")
}
@@ -358,11 +354,12 @@ pp.parseLabeledStatement = function(node, maybeName, expr) {
for (let i = this.labels.length - 1; i >= 0; i--) {
let label = this.labels[i]
if (label.statementStart == node.start) {
+ // Update information about previous labels on this node
label.statementStart = this.start
label.kind = kind
} else break
}
- this.labels.push({name: maybeName, kind: kind, statementStart: this.start})
+ this.labels.push({name: maybeName, kind, statementStart: this.start})
node.body = this.parseStatement(true)
if (node.body.type == "ClassDeclaration" ||
node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
@@ -423,8 +420,14 @@ pp.parseFor = function(node, init) {
pp.parseForIn = function(node, init) {
let type = this.type === tt._in ? "ForInStatement" : "ForOfStatement"
this.next()
+ if (type == "ForInStatement") {
+ if (init.type === "AssignmentPattern" ||
+ (init.type === "VariableDeclaration" && init.declarations[0].init != null &&
+ (this.strict || init.declarations[0].id.type !== "Identifier")))
+ this.raise(init.start, "Invalid assignment in for-in loop head")
+ }
node.left = init
- node.right = this.parseExpression()
+ node.right = type == "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign()
this.expect(tt.parenR)
this.exitLexicalScope()
node.body = this.parseStatement(false)
@@ -519,62 +522,66 @@ pp.parseClass = function(node, isStatement) {
classBody.body = []
this.expect(tt.braceL)
while (!this.eat(tt.braceR)) {
- if (this.eat(tt.semi)) continue
- let method = this.startNode()
- let isGenerator = this.eat(tt.star)
- let isAsync = false
- let isMaybeStatic = this.type === tt.name && this.value === "static"
- this.parsePropertyName(method)
- method.static = isMaybeStatic && this.type !== tt.parenL
- if (method.static) {
- if (isGenerator) this.unexpected()
- isGenerator = this.eat(tt.star)
- this.parsePropertyName(method)
- }
- if (this.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
- method.key.type === "Identifier" && method.key.name === "async" && this.type !== tt.parenL &&
- !this.canInsertSemicolon()) {
- isAsync = true
- this.parsePropertyName(method)
- }
- method.kind = "method"
- let isGetSet = false
- if (!method.computed) {
- let {key} = method
- if (!isGenerator && !isAsync && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
- isGetSet = true
- method.kind = key.name
- key = this.parsePropertyName(method)
- }
- if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
- key.type === "Literal" && key.value === "constructor")) {
- if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class")
- if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier")
- if (isGenerator) this.raise(key.start, "Constructor can't be a generator")
- if (isAsync) this.raise(key.start, "Constructor can't be an async method")
- method.kind = "constructor"
- hadConstructor = true
- }
- }
- this.parseClassMethod(classBody, method, isGenerator, isAsync)
- if (isGetSet) {
- let paramCount = method.kind === "get" ? 0 : 1
- if (method.value.params.length !== paramCount) {
- let start = method.value.start
- if (method.kind === "get")
- this.raiseRecoverable(start, "getter should have no params")
- else
- this.raiseRecoverable(start, "setter should have exactly one param")
- } else {
- if (method.kind === "set" && method.value.params[0].type === "RestElement")
- this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params")
- }
+ const member = this.parseClassMember(classBody)
+ if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
+ if (hadConstructor) this.raise(member.start, "Duplicate constructor in the same class")
+ hadConstructor = true
}
}
node.body = this.finishNode(classBody, "ClassBody")
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
}
+pp.parseClassMember = function(classBody) {
+ if (this.eat(tt.semi)) return null
+
+ let method = this.startNode()
+ const tryContextual = (k, noLineBreak = false) => {
+ const start = this.start, startLoc = this.startLoc
+ if (!this.eatContextual(k)) return false
+ if (this.type !== tt.parenL && (!noLineBreak || !this.canInsertSemicolon())) return true
+ if (method.key) this.unexpected()
+ method.computed = false
+ method.key = this.startNodeAt(start, startLoc)
+ method.key.name = k
+ this.finishNode(method.key, "Identifier")
+ return false
+ }
+
+ method.kind = "method"
+ method.static = tryContextual("static")
+ let isGenerator = this.eat(tt.star)
+ let isAsync = false
+ if (!isGenerator) {
+ if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
+ isAsync = true
+ } else if (tryContextual("get")) {
+ method.kind = "get"
+ } else if (tryContextual("set")) {
+ method.kind = "set"
+ }
+ }
+ if (!method.key) this.parsePropertyName(method)
+ let {key} = method
+ if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
+ key.type === "Literal" && key.value === "constructor")) {
+ if (method.kind !== "method") this.raise(key.start, "Constructor can't have get/set modifier")
+ if (isGenerator) this.raise(key.start, "Constructor can't be a generator")
+ if (isAsync) this.raise(key.start, "Constructor can't be an async method")
+ method.kind = "constructor"
+ } else if (method.static && key.type === "Identifier" && key.name === "prototype") {
+ this.raise(key.start, "Classes may not have a static property named prototype")
+ }
+ this.parseClassMethod(classBody, method, isGenerator, isAsync)
+ if (method.kind === "get" && method.value.params.length !== 0)
+ this.raiseRecoverable(method.value.start, "getter should have no params")
+ if (method.kind === "set" && method.value.params.length !== 1)
+ this.raiseRecoverable(method.value.start, "setter should have exactly one param")
+ if (method.kind === "set" && method.value.params[0].type === "RestElement")
+ this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params")
+ return method
+}
+
pp.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
method.value = this.parseMethod(isGenerator, isAsync)
classBody.body.push(this.finishNode(method, "MethodDefinition"))
@@ -595,7 +602,8 @@ pp.parseExport = function(node, exports) {
// export * from '...'
if (this.eat(tt.star)) {
this.expectContextual("from")
- node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
+ if (this.type !== tt.string) this.unexpected()
+ node.source = this.parseExprAtom()
this.semicolon()
return this.finishNode(node, "ExportAllDeclaration")
}
@@ -629,7 +637,8 @@ pp.parseExport = function(node, exports) {
node.declaration = null
node.specifiers = this.parseExportSpecifiers(exports)
if (this.eatContextual("from")) {
- node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
+ if (this.type !== tt.string) this.unexpected()
+ node.source = this.parseExprAtom()
} else {
// check for keywords used as local names
for (let spec of node.specifiers) {
diff --git a/src/tokenize.js b/src/tokenize.js
index f2611b0..27d6971 100644
--- a/src/tokenize.js
+++ b/src/tokenize.js
@@ -291,12 +291,12 @@ pp.readToken_eq_excl = function(code) { // '=!'
pp.getTokenFromCode = function(code) {
switch (code) {
- // The interpretation of a dot depends on whether it is followed
- // by a digit or another two dots.
+ // The interpretation of a dot depends on whether it is followed
+ // by a digit or another two dots.
case 46: // '.'
return this.readToken_dot()
- // Punctuation tokens.
+ // Punctuation tokens.
case 40: ++this.pos; return this.finishToken(tt.parenL)
case 41: ++this.pos; return this.finishToken(tt.parenR)
case 59: ++this.pos; return this.finishToken(tt.semi)
@@ -320,19 +320,20 @@ pp.getTokenFromCode = function(code) {
if (next === 111 || next === 79) return this.readRadixNumber(8) // '0o', '0O' - octal number
if (next === 98 || next === 66) return this.readRadixNumber(2) // '0b', '0B' - binary number
}
- // Anything else beginning with a digit is an integer, octal
- // number, or float.
+
+ // Anything else beginning with a digit is an integer, octal
+ // number, or float.
case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
return this.readNumber(false)
- // Quotes produce strings.
+ // Quotes produce strings.
case 34: case 39: // '"', "'"
return this.readString(code)
- // Operators are parsed inline in tiny state machines. '=' (61) is
- // often referred to. `finishOp` simply skips the amount of
- // characters it is given as second argument, and returns a token
- // of the type given by its first argument.
+ // Operators are parsed inline in tiny state machines. '=' (61) is
+ // often referred to. `finishOp` simply skips the amount of
+ // characters it is given as second argument, and returns a token
+ // of the type given by its first argument.
case 47: // '/'
return this.readToken_slash()
@@ -407,6 +408,7 @@ pp.readRegexp = function() {
if (mods) {
let validFlags = /^[gim]*$/
if (this.options.ecmaVersion >= 6) validFlags = /^[gimuy]*$/
+ if (this.options.ecmaVersion >= 9) validFlags = /^[gimsuy]*$/
if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag")
if (mods.indexOf("u") >= 0) {
if (regexpUnicodeSupport) {
@@ -475,30 +477,26 @@ pp.readRadixNumber = function(radix) {
// Read an integer, octal integer, or floating-point number.
pp.readNumber = function(startsWithDot) {
- let start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48
+ let start = this.pos
if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number")
- if (octal && this.pos == start + 1) octal = false
+ let octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48
+ if (octal && this.strict) this.raise(start, "Invalid number")
+ if (octal && /[89]/.test(this.input.slice(start, this.pos))) octal = false
let next = this.input.charCodeAt(this.pos)
if (next === 46 && !octal) { // '.'
++this.pos
this.readInt(10)
- isFloat = true
next = this.input.charCodeAt(this.pos)
}
if ((next === 69 || next === 101) && !octal) { // 'eE'
next = this.input.charCodeAt(++this.pos)
if (next === 43 || next === 45) ++this.pos // '+-'
if (this.readInt(10) === null) this.raise(start, "Invalid number")
- isFloat = true
}
if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number")
- let str = this.input.slice(start, this.pos), val
- if (isFloat) val = parseFloat(str)
- else if (!octal || str.length === 1) val = parseInt(str, 10)
- else if (this.strict) this.raise(start, "Invalid number")
- else if (/[89]/.test(str)) val = parseInt(str, 10)
- else val = parseInt(str, 8)
+ let str = this.input.slice(start, this.pos)
+ let val = octal ? parseInt(str, 8) : parseFloat(str)
return this.finishToken(tt.num, val)
}
diff --git a/src/walk/index.js b/src/walk/index.js
index 28f42ff..d644087 100644
--- a/src/walk/index.js
+++ b/src/walk/index.js
@@ -214,6 +214,11 @@ base.SwitchStatement = (node, st, c) => {
c(cons, st, "Statement")
}
}
+base.SwitchCase = (node, st, c) => {
+ if (node.test) c(node.test, st, "Expression")
+ for (let cons of node.consequent)
+ c(cons, st, "Statement")
+}
base.ReturnStatement = base.YieldExpression = base.AwaitExpression = (node, st, c) => {
if (node.argument) c(node.argument, st, "Expression")
}
diff --git a/test/tests-asyncawait.js b/test/tests-asyncawait.js
index 338ed91..15c1ac2 100644
--- a/test/tests-asyncawait.js
+++ b/test/tests-asyncawait.js
@@ -1669,11 +1669,11 @@ test("await", {
}, {ecmaVersion: 8})
// 'await' is a keyword in modules.
-testFail("await", "The keyword 'await' is reserved (1:0)", {ecmaVersion: 8, sourceType: "module"})
+testFail("await", "Can not use keyword 'await' outside an async function (1:0)", {ecmaVersion: 8, sourceType: "module"})
// Await expressions is invalid outside of async functions.
testFail("await a", "Unexpected token (1:6)", {ecmaVersion: 8})
-testFail("await a", "The keyword 'await' is reserved (1:0)", {ecmaVersion: 8, sourceType: "module"})
+testFail("await a", "Can not use keyword 'await' outside an async function (1:0)", {ecmaVersion: 8, sourceType: "module"})
// Await expressions in async functions.
test("async function foo(a, b) { await a }", {
@@ -2766,7 +2766,7 @@ test("function* wrap() {\nasync(a = yield b)\n}", {
}, {ecmaVersion: 8})
testFail("function* wrap() {\nasync(a = yield b) => a\n}", "Yield expression cannot be a default value (2:10)", {ecmaVersion: 8})
-// https://github.com/ternjs/acorn/issues/464
+// https://github.com/acornjs/acorn/issues/464
test("f = ({ w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }) => {}", {
"type": "Program",
"start": 0,
@@ -3092,21 +3092,7 @@ test("({ async: true })", {
}, {ecmaVersion: 8});
// Tests for B.3.4 FunctionDeclarations in IfStatement Statement Clauses
-test(
- "if (x) async function f() {}",
- {
- type: "Program",
- body: [{
- type: "IfStatement",
- consequent: {
- type: "FunctionDeclaration",
- async: true
- },
- alternate: null
- }]
- },
- {ecmaVersion: 8}
-)
+testFail("if (x) async function f() {}", "Unexpected token (1:7)", {ecmaVersion: 8})
testFail("(async)(a) => 12", "Unexpected token (1:11)", {ecmaVersion: 8})
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index 6ed18e6..3f9b401 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -3132,6 +3132,105 @@ test("[a, b] = [b, a]", {
locations: true
});
+test("[a.r] = b", {
+ "type": "Program",
+ "start": 0,
+ "end": 9,
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 9,
+ "expression": {
+ "type": "AssignmentExpression",
+ "start": 0,
+ "end": 9,
+ "operator": "=",
+ "left": {
+ "type": "ArrayPattern",
+ "start": 0,
+ "end": 5,
+ "elements": [
+ {
+ "type": "MemberExpression",
+ "start": 1,
+ "end": 4,
+ "object": {
+ "type": "Identifier",
+ "start": 1,
+ "end": 2,
+ "name": "a"
+ },
+ "property": {
+ "type": "Identifier",
+ "start": 3,
+ "end": 4,
+ "name": "r"
+ },
+ "computed": false
+ }
+ ]
+ },
+ "right": {
+ "type": "Identifier",
+ "start": 8,
+ "end": 9,
+ "name": "b"
+ }
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 6})
+
+test("let [a,,b] = c", {
+ "type": "Program",
+ "start": 0,
+ "end": 14,
+ "body": [
+ {
+ "type": "VariableDeclaration",
+ "start": 0,
+ "end": 14,
+ "declarations": [
+ {
+ "type": "VariableDeclarator",
+ "start": 4,
+ "end": 14,
+ "id": {
+ "type": "ArrayPattern",
+ "start": 4,
+ "end": 10,
+ "elements": [
+ {
+ "type": "Identifier",
+ "start": 5,
+ "end": 6,
+ "name": "a"
+ },
+ null,
+ {
+ "type": "Identifier",
+ "start": 8,
+ "end": 9,
+ "name": "b"
+ }
+ ]
+ },
+ "init": {
+ "type": "Identifier",
+ "start": 13,
+ "end": 14,
+ "name": "c"
+ }
+ }
+ ],
+ "kind": "let"
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 6})
+
test("({ responseText: text } = res)", {
type: "Program",
body: [{
@@ -3868,7 +3967,7 @@ test("export var document = { }", {
locations: true
});
-testFail("export var await", "The keyword 'await' is reserved (1:11)", { ecmaVersion: 6, sourceType: "module" })
+testFail("export var await", "Can not use keyword 'await' outside an async function (1:11)", { ecmaVersion: 6, sourceType: "module" })
test("export let document", {
type: "Program",
@@ -4985,6 +5084,10 @@ testFail("import * as class from 'foo'", "Unexpected keyword 'class' (1:12)", {e
testFail("import { enum } from 'foo'", "The keyword 'enum' is reserved (1:9)", {ecmaVersion: 6, sourceType: "module" });
testFail("import { a as enum } from 'foo'", "The keyword 'enum' is reserved (1:14)", {ecmaVersion: 6, sourceType: "module" });
testFail("import * as enum from 'foo'", "The keyword 'enum' is reserved (1:12)", {ecmaVersion: 6, sourceType: "module" });
+testFail("() => { class a extends b { static get prototype(){} } }", "Classes may not have a static property named prototype (1:39)", {ecmaVersion: 6});
+testFail("class a extends b { static set prototype(){} }", "Classes may not have a static property named prototype (1:31)", {ecmaVersion: 6});
+testFail("class a { static prototype(){} }", "Classes may not have a static property named prototype (1:17)", {ecmaVersion: 6});
+
// Harmony: Yield Expression
@@ -6763,6 +6866,64 @@ test("class A { static *gen(v) { yield v; }}", {
locations: true
});
+testFail("(class { *static x() {} })", "Unexpected token (1:17)", {ecmaVersion: 6});
+test("(class { *static() {} })", {
+ "type": "Program",
+ "start": 0,
+ "end": 24,
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 24,
+ "expression": {
+ "type": "ClassExpression",
+ "start": 1,
+ "end": 23,
+ "id": null,
+ "superClass": null,
+ "body": {
+ "type": "ClassBody",
+ "start": 7,
+ "end": 23,
+ "body": [
+ {
+ "type": "MethodDefinition",
+ "start": 9,
+ "end": 21,
+ "computed": false,
+ "key": {
+ "type": "Identifier",
+ "start": 10,
+ "end": 16,
+ "name": "static"
+ },
+ "static": false,
+ "kind": "method",
+ "value": {
+ "type": "FunctionExpression",
+ "start": 16,
+ "end": 21,
+ "id": null,
+ "generator": true,
+ "expression": false,
+ "params": [],
+ "body": {
+ "type": "BlockStatement",
+ "start": 19,
+ "end": 21,
+ "body": []
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 6});
+
test("\"use strict\"; (class A {constructor() { super() }})", {
type: "Program",
body: [
@@ -6911,9 +7072,66 @@ test("class A {'constructor'() {}}", {
}]
}, {ecmaVersion: 6});
-testFail("class A { constructor() {} 'constructor'() }", "Duplicate constructor in the same class (1:27)", {ecmaVersion: 6});
+testFail("class A { constructor() {} 'constructor'() {} }", "Duplicate constructor in the same class (1:27)", {ecmaVersion: 6});
testFail("class A { get constructor() {} }", "Constructor can't have get/set modifier (1:14)", {ecmaVersion: 6});
+test("class A { get ['constructor']() {} }", {
+ "type": "Program",
+ "start": 0,
+ "end": 36,
+ "body": [
+ {
+ "type": "ClassDeclaration",
+ "start": 0,
+ "end": 36,
+ "id": {
+ "type": "Identifier",
+ "start": 6,
+ "end": 7,
+ "name": "A"
+ },
+ "superClass": null,
+ "body": {
+ "type": "ClassBody",
+ "start": 8,
+ "end": 36,
+ "body": [
+ {
+ "type": "MethodDefinition",
+ "start": 10,
+ "end": 34,
+ "static": false,
+ "computed": true,
+ "key": {
+ "type": "Literal",
+ "start": 15,
+ "end": 28,
+ "value": "constructor",
+ "raw": "'constructor'"
+ },
+ "kind": "get",
+ "value": {
+ "type": "FunctionExpression",
+ "start": 29,
+ "end": 34,
+ "id": null,
+ "params": [],
+ "generator": false,
+ "expression": false,
+ "body": {
+ "type": "BlockStatement",
+ "start": 32,
+ "end": 34,
+ "body": []
+ }
+ }
+ }
+ ]
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 6});
testFail("class A { *constructor() {} }", "Constructor can't be a generator (1:11)", {ecmaVersion: 6});
@@ -10592,8 +10810,10 @@ test("function x({ a, b }){}", {
});
testFail("function x(...[ a, b ]){}", "Unexpected token (1:14)", {ecmaVersion: 6});
+testFail("(([...[ a, b ]]) => {})", "Unexpected token (1:6)", {ecmaVersion: 6});
testFail("function x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){}", "Unexpected token (1:42)", {ecmaVersion: 6});
+testFail("(function ({ a(){} }) {})", "Unexpected token (1:14)", {ecmaVersion: 6});
test("(function x([ a, b ]){})", {
type: "Program",
@@ -12696,7 +12916,7 @@ testFail("var super", "Unexpected keyword 'super' (1:4)", {ecmaVersion: 6});
testFail("var default", "Unexpected keyword 'default' (1:4)", {ecmaVersion: 6});
-testFail("let default", "Unexpected token (1:4)", {ecmaVersion: 6});
+testFail("let default", "Unexpected keyword 'default' (1:4)", {ecmaVersion: 6});
testFail("const default", "Unexpected keyword 'default' (1:6)", {ecmaVersion: 6});
@@ -13036,6 +13256,8 @@ testFail("({ 42 }) = obj", "Unexpected token (1:6)", {ecmaVersion: 6});
testFail("function f(a, ...b, c)", "Comma is not permitted after the rest element (1:18)", {ecmaVersion: 6});
testFail("function f(a, ...b = 0)", "Unexpected token (1:19)", {ecmaVersion: 6});
+testFail("(([a, ...b = 0]) => {})", "Rest elements cannot have a default value (1:9)", {ecmaVersion: 7});
+testFail("[a, ...b = 0] = []", "Rest elements cannot have a default value (1:7)", {ecmaVersion: 6});
testFail("function x(...{ a }){}", "Unexpected token (1:14)", {ecmaVersion: 6});
@@ -13079,7 +13301,7 @@ testFail("({ get test() { } }) => 42", "Object pattern can't contain getter or s
/* Regression tests */
-// # https://github.com/ternjs/acorn/issues/127
+// # https://github.com/acornjs/acorn/issues/127
test('doSmth(`${x} + ${y} = ${x + y}`)', {
type: "Program",
body: [{
@@ -13141,7 +13363,7 @@ test('doSmth(`${x} + ${y} = ${x + y}`)', {
}]
}, {ecmaVersion: 6});
-// # https://github.com/ternjs/acorn/issues/129
+// # https://github.com/acornjs/acorn/issues/129
test('function normal(x, y = 10) {}', {
type: "Program",
body: [{
@@ -13189,7 +13411,7 @@ test("() => 42", {
}]
}, {ecmaVersion: 6, preserveParens: true});
-// https://github.com/ternjs/acorn/issues/161
+// https://github.com/acornjs/acorn/issues/161
test("import foo, * as bar from 'baz';", {
type: "Program",
body: [{
@@ -13218,7 +13440,7 @@ test("import foo, * as bar from 'baz';", {
}]
}, {ecmaVersion: 6, sourceType: "module"});
-// https://github.com/ternjs/acorn/issues/173
+// https://github.com/acornjs/acorn/issues/173
test("`{${x}}`, `}`", {
type: "Program",
body: [{
@@ -13259,7 +13481,7 @@ test("`{${x}}`, `}`", {
}]
}, {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/186
+// https://github.com/acornjs/acorn/issues/186
test('var {get} = obj;', {
type: "Program",
body: [{
@@ -13293,7 +13515,7 @@ test('var {get} = obj;', {
}]
}, {ecmaVersion: 6});
-// Destructuring defaults (https://github.com/ternjs/acorn/issues/181)
+// Destructuring defaults (https://github.com/acornjs/acorn/issues/181)
test("var {propName: localVar = defaultValue} = obj", {
type: "Program",
@@ -13743,7 +13965,9 @@ testFail("obj = {x = 0}", "Shorthand property assignments are valid only in dest
testFail("f({x = 0})", "Shorthand property assignments are valid only in destructuring patterns (1:5)", {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/191
+testFail("(localVar |= defaultValue) => {}", "Only '=' operator can be used for specifying default value. (1:9)", {loose: false, ecmaVersion: 6});
+
+// https://github.com/acornjs/acorn/issues/191
test("try {} catch ({message}) {}", {
type: "Program",
@@ -13795,7 +14019,7 @@ test("try {} catch ({message}) {}", {
locations: true
});
-// https://github.com/ternjs/acorn/issues/192
+// https://github.com/acornjs/acorn/issues/192
test("class A { static() {} }", {
type: "Program",
@@ -13845,7 +14069,7 @@ test("class A { static() {} }", {
locations: true
});
-// https://github.com/ternjs/acorn/issues/213
+// https://github.com/acornjs/acorn/issues/213
test("for (const x of list) process(x);", {
type: "Program",
@@ -14365,11 +14589,11 @@ test("export default function foo() {} false", {
type: "Program"
}, {ecmaVersion: 6, sourceType: "module"})
-// https://github.com/ternjs/acorn/issues/274
+// https://github.com/acornjs/acorn/issues/274
testFail("`\\07`", "Octal literal in strict mode (1:1)", {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/277
+// https://github.com/acornjs/acorn/issues/277
testFail("x = { method() 42 }", "Unexpected token (1:15)", {ecmaVersion: 6});
@@ -14377,21 +14601,21 @@ testFail("x = { get method() 42 }", "Unexpected token (1:19)", {ecmaVersion: 6})
testFail("x = { set method(val) v = val }", "Unexpected token (1:22)", {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/278
+// https://github.com/acornjs/acorn/issues/278
testFail("/\\u{110000}/u", "~", {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/279
+// https://github.com/acornjs/acorn/issues/279
testFail("super", "'super' outside of function or class (1:0)", {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/275
+// https://github.com/acornjs/acorn/issues/275
testFail("class A { get prop(x) {} }", "getter should have no params (1:18)", {ecmaVersion: 6});
testFail("class A { set prop() {} }", "setter should have exactly one param (1:18)", {ecmaVersion: 6});
testFail("class A { set prop(x, y) {} }", "setter should have exactly one param (1:18)", {ecmaVersion: 6});
-// https://github.com/ternjs/acorn/issues/276
+// https://github.com/acornjs/acorn/issues/276
testFail("({ __proto__: 1, __proto__: 2 })", "Redefinition of __proto__ property (1:17)", {ecmaVersion: 6});
testFail("({ '__proto__': 1, __proto__: 2 })", "Redefinition of __proto__ property (1:19)", {ecmaVersion: 6});
@@ -14399,9 +14623,30 @@ test("({ ['__proto__']: 1, __proto__: 2 })", {}, {ecmaVersion: 6});
test("({ __proto__() { return 1 }, __proto__: 2 })", {}, {ecmaVersion: 6});
test("({ get __proto__() { return 1 }, __proto__: 2 })", {}, {ecmaVersion: 6});
test("({ __proto__, __proto__: 2 })", {}, {ecmaVersion: 6});
+test("({__proto__: a, __proto__: b} = {})", {}, {ecmaVersion: 6});
test("export default /foo/", {}, {ecmaVersion: 6, sourceType: "module"});
+test("l\\u0065t\na", {
+ "type": "Program",
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "Identifier",
+ "name": "let"
+ }
+ },
+ {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "Identifier",
+ "name": "a"
+ }
+ }
+ ]
+}, {ecmaVersion: 6});
+
test("var await = 0", {
type: "Program",
start: 0,
@@ -14491,14 +14736,14 @@ test("var await = 0", {
allowReserved: false,
locations: true
})
-testFail("var await = 0", "The keyword 'await' is reserved (1:4)", {
+testFail("var await = 0", "Can not use keyword 'await' outside an async function (1:4)", {
ecmaVersion: 6,
sourceType: "module",
allowReserved: false,
locations: true
})
-// https://github.com/ternjs/acorn/issues/363
+// https://github.com/acornjs/acorn/issues/363
test("/[a-z]/gimuy", {
type: "Program",
@@ -14516,6 +14761,29 @@ test("/[a-z]/gimuy", {
]
}, {ecmaVersion: 6});
testFail("/[a-z]/s", "Invalid regular expression flag (1:1)", {ecmaVersion: 6});
+test("/[a-z]/s", {
+ "type": "Program",
+ "start": 0,
+ "end": 8,
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 8,
+ "expression": {
+ "type": "Literal",
+ "start": 0,
+ "end": 8,
+ "raw": "/[a-z]/s",
+ "regex": {
+ "pattern": "[a-z]",
+ "flags": "s"
+ }
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 9});
testFail("[...x in y] = []", "Assigning to rvalue (1:4)", {ecmaVersion: 6});
@@ -15647,6 +15915,8 @@ test("export { default as y } from './y.js';\nexport default 42;",
testFail("export { default} from './y.js';\nexport default 42;",
"Duplicate export 'default' (2:7)",
{sourceType: "module", ecmaVersion: 6})
+testFail("export * from foo", "Unexpected token (1:14)", {sourceType: "module", ecmaVersion: 6, loose: false});
+testFail("export { bar } from foo", "Unexpected token (1:20)", {sourceType: "module", ecmaVersion: 6, loose: false});
testFail("foo: class X {}", "Invalid labeled declaration (1:5)", {ecmaVersion: 6})
@@ -15835,3 +16105,133 @@ test("let instanceof Foo", {
],
"sourceType": "script"
}, {ecmaVersion: 6})
+
+test("function fn({__proto__: a, __proto__: b}) {}", {}, {ecmaVersion: 6})
+
+testFail("for (let x of y, z) {}", "Unexpected token (1:15)", {ecmaVersion: 6})
+
+testFail('[...foo, bar] = b', "Comma is not permitted after the rest element (1:7)", { ecmaVersion: 6 })
+test('[...a, x][1] = b', {
+ "type": "Program",
+ "start": 0,
+ "end": 16,
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 16,
+ "expression": {
+ "type": "AssignmentExpression",
+ "start": 0,
+ "end": 16,
+ "operator": "=",
+ "left": {
+ "type": "MemberExpression",
+ "start": 0,
+ "end": 12,
+ "object": {
+ "type": "ArrayExpression",
+ "start": 0,
+ "end": 9,
+ "elements": [
+ {
+ "type": "SpreadElement",
+ "start": 1,
+ "end": 5,
+ "argument": {
+ "type": "Identifier",
+ "start": 4,
+ "end": 5,
+ "name": "a"
+ }
+ },
+ {
+ "type": "Identifier",
+ "start": 7,
+ "end": 8,
+ "name": "x"
+ }
+ ]
+ },
+ "property": {
+ "type": "Literal",
+ "start": 10,
+ "end": 11,
+ "value": 1,
+ "raw": "1"
+ },
+ "computed": true
+ },
+ "right": {
+ "type": "Identifier",
+ "start": 15,
+ "end": 16,
+ "name": "b"
+ }
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 6})
+
+testFail('for (let [...foo, bar] in qux);', "Comma is not permitted after the rest element (1:16)", { ecmaVersion: 6 })
+test('for ([...foo, bar].baz in qux);', {
+ "type": "Program",
+ "start": 0,
+ "end": 31,
+ "body": [
+ {
+ "type": "ForInStatement",
+ "start": 0,
+ "end": 31,
+ "left": {
+ "type": "MemberExpression",
+ "start": 5,
+ "end": 22,
+ "object": {
+ "type": "ArrayExpression",
+ "start": 5,
+ "end": 18,
+ "elements": [
+ {
+ "type": "SpreadElement",
+ "start": 6,
+ "end": 12,
+ "argument": {
+ "type": "Identifier",
+ "start": 9,
+ "end": 12,
+ "name": "foo"
+ }
+ },
+ {
+ "type": "Identifier",
+ "start": 14,
+ "end": 17,
+ "name": "bar"
+ }
+ ]
+ },
+ "property": {
+ "type": "Identifier",
+ "start": 19,
+ "end": 22,
+ "name": "baz"
+ },
+ "computed": false
+ },
+ "right": {
+ "type": "Identifier",
+ "start": 26,
+ "end": 29,
+ "name": "qux"
+ },
+ "body": {
+ "type": "EmptyStatement",
+ "start": 30,
+ "end": 31
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 6})
diff --git a/test/tests.js b/test/tests.js
index 25ac432..53a4882 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -19672,6 +19672,9 @@ test("for (var x in list) process(x);", {
}
}
});
+testFail("var x; for (x = 0 in list) process(x);", "Invalid assignment in for-in loop head (1:12)", { ecmaVersion: 6 })
+testFail("'use strict'; for (var x = 0 in list) process(x);", "Invalid assignment in for-in loop head (1:19)")
+testFail("for (var [x] = 0 in list) process(x);", "Invalid assignment in for-in loop head (1:5)", { ecmaVersion: 6 })
test("for (var x = 42 in list) process(x);", {
type: "Program",
@@ -20720,6 +20723,57 @@ test("done: while (true) { break done; }", {
}
});
+test("done: switch (a) { default: break done }", {
+ "type": "Program",
+ "start": 0,
+ "end": 40,
+ "body": [
+ {
+ "type": "LabeledStatement",
+ "start": 0,
+ "end": 40,
+ "body": {
+ "type": "SwitchStatement",
+ "start": 6,
+ "end": 40,
+ "discriminant": {
+ "type": "Identifier",
+ "start": 14,
+ "end": 15,
+ "name": "a"
+ },
+ "cases": [
+ {
+ "type": "SwitchCase",
+ "start": 19,
+ "end": 38,
+ "consequent": [
+ {
+ "type": "BreakStatement",
+ "start": 28,
+ "end": 38,
+ "label": {
+ "type": "Identifier",
+ "start": 34,
+ "end": 38,
+ "name": "done"
+ }
+ }
+ ],
+ "test": null
+ }
+ ]
+ },
+ "label": {
+ "type": "Identifier",
+ "start": 0,
+ "end": 4,
+ "name": "done"
+ }
+ }
+ ]
+});
+
test("target1: target2: while (true) { continue target1; }", {});
test("target1: target2: target3: while (true) { continue target1; }", {});
@@ -26387,6 +26441,55 @@ test("foo: if (true) break foo;", {
]
});
+test("a: { b: switch(x) {} }", {
+ "type": "Program",
+ "start": 0,
+ "end": 22,
+ "body": [
+ {
+ "type": "LabeledStatement",
+ "start": 0,
+ "end": 22,
+ "body": {
+ "type": "BlockStatement",
+ "start": 3,
+ "end": 22,
+ "body": [
+ {
+ "type": "LabeledStatement",
+ "start": 5,
+ "end": 20,
+ "body": {
+ "type": "SwitchStatement",
+ "start": 8,
+ "end": 20,
+ "discriminant": {
+ "type": "Identifier",
+ "start": 15,
+ "end": 16,
+ "name": "x"
+ },
+ "cases": []
+ },
+ "label": {
+ "type": "Identifier",
+ "start": 5,
+ "end": 6,
+ "name": "b"
+ }
+ }
+ ]
+ },
+ "label": {
+ "type": "Identifier",
+ "start": 0,
+ "end": 1,
+ "name": "a"
+ }
+ }
+ ]
+});
+
test("(function () {\n 'use strict';\n '\0';\n}())", {
type: "Program",
loc: {
@@ -27003,7 +27106,7 @@ testFail("--1",
"Assigning to rvalue (1:2)");
testFail("for((1 + 1) in list) process(x);",
- "Assigning to rvalue (1:5)");
+ "Parenthesized pattern (1:4)");
testFail("[",
"Unexpected token (1:1)");
@@ -27511,7 +27614,11 @@ testFail("for(const x = 0;;);", "The keyword 'const' is reserved (1:4)");
testFail("for(let x = 0;;);", "Unexpected token (1:8)");
-testFail("function a(b = c) {}", "Unexpected token (1:13)")
+testFail("function a(b = c) {}", "Unexpected token (1:13)");
+
+testFail("switch (x) { something }", "Unexpected token (1:13)");
+
+testFail("`abc`", "Unexpected character '`' (1:0)", {ecmaVersion: 5});
test("let++", {
type: "Program",
@@ -29002,7 +29109,7 @@ test('var x = (1 + 2)', {}, {
test("function f(f) { 'use strict'; }", {});
-// https://github.com/ternjs/acorn/issues/180
+// https://github.com/acornjs/acorn/issues/180
test("#!/usr/bin/node\n;", {}, {
allowHashBang: true,
onComment: [{
@@ -29013,7 +29120,7 @@ test("#!/usr/bin/node\n;", {}, {
}]
});
-// https://github.com/ternjs/acorn/issues/204
+// https://github.com/acornjs/acorn/issues/204
test("(function () {} / 1)", {
type: "Program",
body: [{
@@ -29058,7 +29165,7 @@ test("function f() {} / 1 /", {
]
});
-// https://github.com/ternjs/acorn/issues/320
+// https://github.com/acornjs/acorn/issues/320
test("do /x/; while (false);", {
type: "Program",
@@ -29102,13 +29209,13 @@ testAssert("[1,2,] + {foo: 1,}", function() {
}, {onTrailingComma: function(pos) { trailingCommas.push(pos); },
loose: false})
-// https://github.com/ternjs/acorn/issues/275
+// https://github.com/acornjs/acorn/issues/275
testFail("({ get prop(x) {} })", "getter should have no params (1:11)");
testFail("({ set prop() {} })", "setter should have exactly one param (1:11)");
testFail("({ set prop(x, y) {} })", "setter should have exactly one param (1:11)");
-// https://github.com/ternjs/acorn/issues/363
+// https://github.com/acornjs/acorn/issues/363
test("/[a-z]/gim", {
type: "Program",
@@ -29184,9 +29291,67 @@ test("0128", {
]
})
+testFail("07.5", "Unexpected token (1:2)")
+
+test("08.5", {
+ "type": "Program",
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "expression": {
+ "type": "Literal",
+ "value": 8.5,
+ "raw": "08.5"
+ }
+ }
+ ]
+})
+
test("undefined", {}, { ecmaVersion: 8 })
testFail("\\u{74}rue", "Escape sequence in keyword true (1:0)", {ecmaVersion: 6})
+testFail("export { X \\u0061s Y }", "Unexpected token (1:11)", {ecmaVersion: 7, sourceType: "module"})
+testFail("import X fro\\u006d 'x'", "Unexpected token (1:9)", {ecmaVersion: 7, sourceType: "module"})
+testFail("le\\u0074 x = 5", "Unexpected token (1:9)", {ecmaVersion: 6})
+testFail("(function* () { y\\u0069eld 10 })", "Can not use 'yield' as identifier inside a generator (1:16)", {ecmaVersion: 6})
+testFail("(async function() { aw\\u0061it x })", "Can not use 'await' as identifier inside an async function (1:20)", {ecmaVersion: 8})
+testFail("(\\u0061sync function() { await x })", "Unexpected token (1:12)", {ecmaVersion: 8})
+testFail("(\\u0061sync () => { await x })", "Unexpected token (1:15)", {ecmaVersion: 8})
+testFail("\\u0061sync x => { await x }", "Unexpected token (1:11)", {ecmaVersion: 8})
+testFail("class X { \\u0061sync x() { await x } }", "Unexpected token (1:21)", {ecmaVersion: 8})
+testFail("class X { static \\u0061sync x() { await x } }", "Unexpected token (1:28)", {ecmaVersion: 8})
+testFail("({ ge\\u0074 x() {} })", "Unexpected token (1:12)")
+testFail("export \\u0061sync function y() { await x }", "Unexpected token (1:7)", {ecmaVersion: 8, sourceType: "module"})
+testFail("export default \\u0061sync function () { await x }", "Unexpected token (1:26)", {ecmaVersion: 8, sourceType: "module"})
+test("(\\u0061sync ())", {
+ "type": "Program",
+ "start": 0,
+ "end": 15,
+ "body": [
+ {
+ "type": "ExpressionStatement",
+ "start": 0,
+ "end": 15,
+ "expression": {
+ "type": "CallExpression",
+ "start": 1,
+ "end": 14,
+ "callee": {
+ "type": "Identifier",
+ "start": 1,
+ "end": 11,
+ "name": "async"
+ },
+ "arguments": []
+ }
+ }
+ ],
+ "sourceType": "script"
+}, {ecmaVersion: 8})
+testFail("({ \\u0061sync x() { await x } })", "Unexpected token (1:14)", {ecmaVersion: 8})
+testFail("for (x \\u006ff y) {}", "Unexpected token (1:7)", {ecmaVersion: 6})
+testFail("function x () { new.ta\\u0072get }", "The only valid meta property for new is new.target (1:20)", {ecmaVersion: 6})
+testFail("class X { st\\u0061tic y() {} }", "Unexpected token (1:22)", {ecmaVersion: 6})
testFail("(x=1)=2", "Parenthesized pattern (1:0)")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/acorn.git
More information about the Pkg-javascript-commits
mailing list