From a60287328199ecae2122600990237ee6c9452b8c Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 20 Mar 2015 20:05:29 +1100 Subject: [PATCH] update to latest acorn, better array shortcuts, don't add code frame to error message --- src/babel/api/browser.js | 2 +- src/babel/generation/source-map.js | 2 +- src/babel/helpers/code-frame.js | 73 ++++++------ src/babel/helpers/parse.js | 7 +- src/babel/transformation/file/index.js | 24 ++-- .../transformation/file/option-parsers.js | 4 + src/babel/transformation/file/options.json | 15 ++- .../transformation/templates/for-of-loose.js | 2 +- .../templates/sliced-to-array-loose.js | 14 +++ .../templates/sliced-to-array.js | 7 +- .../transformation/templates/to-array.js | 2 +- .../templates/to-consumable-array.js | 2 +- .../transformers/internal/validation.js | 4 + src/babel/traversal/index.js | 5 +- src/babel/traversal/path/index.js | 29 +++-- src/babel/traversal/scope.js | 7 +- src/babel/types/index.js | 1 + src/babel/util.js | 3 +- ...es-not-bind-this-from-standard-function.js | 5 - .../es6-for-of-loose/identifier/expected.js | 2 +- .../es6-for-of-loose/ignore-cases/expected.js | 2 +- .../es6-for-of-loose/let/expected.js | 2 +- .../member-expression/expected.js | 2 +- .../es6-for-of-loose/multiple/expected.js | 4 +- .../es6-for-of-loose/var/expected.js | 2 +- .../es6-spread/arguments-array/expected.js | 3 +- .../es6-spread/arguments-concat/expected.js | 3 +- .../array-literal-first/expected.js | 4 +- .../array-literal-middle/expected.js | 4 +- .../array-literal-multiple/expected.js | 4 +- .../es6-spread/array-literals/expected.js | 4 +- .../expected.js | 4 +- .../expected.js | 4 +- .../expected.js | 6 +- .../expected.js | 6 +- .../es6-spread/method-call-first/expected.js | 4 +- .../es6-spread/method-call-middle/expected.js | 4 +- .../method-call-multiple-args/expected.js | 4 +- .../method-call-multiple/expected.js | 4 +- .../method-call-single-arg/expected.js | 4 +- .../es6-spread/new-expression/expected.js | 8 +- .../transformation/es6-spread/options.json | 7 +- .../es6-spread/single/expected.js | 4 +- test/util.js | 4 +- vendor/acorn/acorn.js | 110 +++++++++--------- vendor/acorn/test/tests-harmony.js | 107 +++++++++++++++++ 46 files changed, 322 insertions(+), 202 deletions(-) create mode 100644 src/babel/transformation/templates/sliced-to-array-loose.js delete mode 100644 test/fixtures/esnext/es6-arrow-functions/does-not-bind-this-from-standard-function.js diff --git a/src/babel/api/browser.js b/src/babel/api/browser.js index 82671a3712..8611775061 100644 --- a/src/babel/api/browser.js +++ b/src/babel/api/browser.js @@ -5,7 +5,7 @@ transform.version = require("../../../package").version; transform.transform = transform; transform.run = function (code, opts = {}) { - opts.sourceMap = "inline"; + opts.sourceMaps = "inline"; return new Function(transform(code, opts).code)(); }; diff --git a/src/babel/generation/source-map.js b/src/babel/generation/source-map.js index 1ce084a365..2f6407ca41 100644 --- a/src/babel/generation/source-map.js +++ b/src/babel/generation/source-map.js @@ -6,7 +6,7 @@ export default class SourceMap { this.position = position; this.opts = opts; - if (opts.sourceMap) { + if (opts.sourceMaps) { this.map = new sourceMap.SourceMapGenerator({ file: opts.sourceMapName, sourceRoot: opts.sourceRoot diff --git a/src/babel/helpers/code-frame.js b/src/babel/helpers/code-frame.js index 8f24c61502..c7c6a1e061 100644 --- a/src/babel/helpers/code-frame.js +++ b/src/babel/helpers/code-frame.js @@ -3,15 +3,13 @@ import repeating from "repeating"; import jsTokens from "js-tokens"; import esutils from "esutils"; import chalk from "chalk"; -import ary from "lodash/function/ary"; var defs = { string: chalk.red, - punctuator: chalk.white.bold, + punctuator: chalk.bold, curly: chalk.green, parens: chalk.blue.bold, square: chalk.yellow, - name: chalk.white, keyword: chalk.cyan, number: chalk.magenta, regex: chalk.magenta, @@ -19,50 +17,51 @@ var defs = { invalid: chalk.inverse }; -var newline = /\r\n|[\n\r\u2028\u2029]/; +const NEWLINE = /\r\n|[\n\r\u2028\u2029]/; -var highlight = function (text) { - var tokenType = function (match) { - var token = jsTokens.matchToToken(match); - if (token.type === "name" && esutils.keyword.isReservedWordES6(token.value)) { - return "keyword"; +function getTokenType(match) { + var token = jsTokens.matchToToken(match); + if (token.type === "name" && esutils.keyword.isReservedWordES6(token.value)) { + return "keyword"; + } + + if (token.type === "punctuator") { + switch (token.value) { + case "{": + case "}": + return "curly"; + case "(": + case ")": + return "parens"; + case "[": + case "]": + return "square"; } + } - if (token.type === "punctuator") { - switch (token.value) { - case "{": - case "}": - return "curly"; - case "(": - case ")": - return "parens"; - case "[": - case "]": - return "square"; - } + return token.type; +} + +function highlight(text) { + return text.replace(jsTokens, function (...args) { + var type = getTokenType(args); + var colorize = defs[type]; + if (colorize) { + return args[0].split(NEWLINE).map(str => colorize(str)).join("\n"); + } else { + return args[0]; } - - return token.type; - }; - - return text.replace(jsTokens, function (match) { - var type = tokenType(arguments); - if (type in defs) { - var colorize = ary(defs[type], 1); - return match.split(newline).map(colorize).join("\n"); - } - return match; }); -}; +} -export default function (lines: number, lineNumber: number, colNumber: number, color?): string { +export default function (lines: number, lineNumber: number, colNumber: number, opts?): string { colNumber = Math.max(colNumber, 0); - if (color && chalk.supportsColor) { + if (opts.highlightCode && chalk.supportsColor) { lines = highlight(lines); } - lines = lines.split(newline); + lines = lines.split(NEWLINE); var start = Math.max(lineNumber - 3, 0); var end = Math.min(lines.length, lineNumber + 3); @@ -72,7 +71,7 @@ export default function (lines: number, lineNumber: number, colNumber: number, c end = lines.length; } - return "\n" + lineNumbers(lines.slice(start, end), { + return lineNumbers(lines.slice(start, end), { start: start + 1, before: " ", after: " | ", diff --git a/src/babel/helpers/parse.js b/src/babel/helpers/parse.js index 89001810d0..1a6459497d 100644 --- a/src/babel/helpers/parse.js +++ b/src/babel/helpers/parse.js @@ -40,11 +40,12 @@ export default function (opts, code, callback) { if (!err._babel) { err._babel = true; - var message = `${opts.filename}: ${err.message}`; + var message = err.message = `${opts.filename}: ${err.message}`; var loc = err.loc; if (loc) { - message += codeFrame(code, loc.line, loc.column + 1, opts.highlightErrors); + err.codeFrame = codeFrame(code, loc.line, loc.column + 1, opts); + message += "\n" + err.codeFrame; } if (err.stack) { @@ -55,8 +56,6 @@ export default function (opts, code, callback) { // `err.stack` may be a readonly property in some environments } } - - err.message = message; } throw err; diff --git a/src/babel/transformation/file/index.js b/src/babel/transformation/file/index.js index 94135bf91d..65eefee04f 100644 --- a/src/babel/transformation/file/index.js +++ b/src/babel/transformation/file/index.js @@ -65,6 +65,7 @@ export default class File { "to-array", "to-consumable-array", "sliced-to-array", + "sliced-to-array-loose", "object-without-properties", "has-own", "slice", @@ -111,11 +112,15 @@ export default class File { var optionParser = optionParsers[option.type]; if (optionParser) val = optionParser(key, val); - opts[key] = val; + if (option.alias) { + opts[option.alias] ||= val; + } else { + opts[key] = val; + } } if (opts.inputSourceMap) { - opts.sourceMap = true; + opts.sourceMaps = true; } // normalize windows path separators to unix @@ -382,9 +387,9 @@ export default class File { // var parseOpts = { - highlightErrors: opts.highlightErrors, - filename: opts.filename, - plugins: {} + highlightCode: opts.highlightCode, + filename: opts.filename, + plugins: {} }; var features = parseOpts.features = {}; @@ -448,9 +453,8 @@ export default class File { var stack = this.transformerStack; for (var i = 0; i < stack.length; i++) { var transformer = stack[i].transformer; - if (transformer[key]) { - transformer[key](this); - } + var fn = transformer[key]; + if (fn) fn(this); } } @@ -527,11 +531,11 @@ export default class File { result.map = this.mergeSourceMap(result.map); - if (opts.sourceMap === "inline" || opts.sourceMap === "both") { + if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") { result.code += "\n" + convertSourceMap.fromObject(result.map).toComment(); } - if (opts.sourceMap === "inline") { + if (opts.sourceMaps === "inline") { result.map = null; } diff --git a/src/babel/transformation/file/option-parsers.js b/src/babel/transformation/file/option-parsers.js index a0a2cc33d2..d1ee8feba9 100644 --- a/src/babel/transformation/file/option-parsers.js +++ b/src/babel/transformation/file/option-parsers.js @@ -12,6 +12,10 @@ export function transformerList(key, val) { } export function boolean(key, val) { + return !!val; +} + +export function booleanString(key, val) { return util.booleanify(val); } diff --git a/src/babel/transformation/file/options.json b/src/babel/transformation/file/options.json index 9b18d54e15..06f04ef7fe 100644 --- a/src/babel/transformation/file/options.json +++ b/src/babel/transformation/file/options.json @@ -19,8 +19,12 @@ }, - "highlightErrors": { - "description": "ANSI syntax highlight error messages", + "highlightTheme": { + "hidden": true + }, + + "highlightCode": { + "description": "ANSI syntax highlight code frames", "type": "boolean", "default": true }, @@ -135,7 +139,12 @@ }, "sourceMap": { - "type": "string", + "alias": "sourceMaps", + "hidden": true + }, + + "sourceMaps": { + "type": "booleanString", "default": false, "shorthand": "s" }, diff --git a/src/babel/transformation/templates/for-of-loose.js b/src/babel/transformation/templates/for-of-loose.js index 9b463868ce..14c0c7e437 100644 --- a/src/babel/transformation/templates/for-of-loose.js +++ b/src/babel/transformation/templates/for-of-loose.js @@ -1,5 +1,5 @@ for (var LOOP_OBJECT = OBJECT, - IS_ARRAY = Array.isArray(LOOP_OBJECT), + IS_ARRAY = LOOP_OBJECT && LOOP_OBJECT.constructor === Array, INDEX = 0, LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) { var ID; diff --git a/src/babel/transformation/templates/sliced-to-array-loose.js b/src/babel/transformation/templates/sliced-to-array-loose.js new file mode 100644 index 0000000000..b6d8868843 --- /dev/null +++ b/src/babel/transformation/templates/sliced-to-array-loose.js @@ -0,0 +1,14 @@ +(function (arr, i) { + if (arr && arr.constructor === Array) { + return arr; + } else if (Symbol.iterator in Object(arr)) { + var _arr = []; + for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { + _arr.push(_step.value); + if (i && _arr.length === i) break; + } + return _arr; + } else { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); + } +}); diff --git a/src/babel/transformation/templates/sliced-to-array.js b/src/babel/transformation/templates/sliced-to-array.js index aac859f7f4..c35f18e903 100644 --- a/src/babel/transformation/templates/sliced-to-array.js +++ b/src/babel/transformation/templates/sliced-to-array.js @@ -1,5 +1,5 @@ (function (arr, i) { - if (Array.isArray(arr)) { + if (arr && arr.constructor === Array) { return arr; } else if (Symbol.iterator in Object(arr)) { // this is an expanded form of `for...of` that properly supports abrupt completions of @@ -17,9 +17,8 @@ var _d = false; var _e = undefined; try { - for (var _i = arr[Symbol.iterator](), _s; !(_n (_s = _i.next()).done); _n = true) { - var val = _s.value; - _arr.push(_step.value); + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { diff --git a/src/babel/transformation/templates/to-array.js b/src/babel/transformation/templates/to-array.js index c479b65446..42b81bd483 100644 --- a/src/babel/transformation/templates/to-array.js +++ b/src/babel/transformation/templates/to-array.js @@ -1,3 +1,3 @@ (function (arr) { - return Array.isArray(arr) ? arr : Array.from(arr); + return arr && arr.constructor === Array ? arr : Array.from(arr); }); diff --git a/src/babel/transformation/templates/to-consumable-array.js b/src/babel/transformation/templates/to-consumable-array.js index 9e042dadf1..711657e96b 100644 --- a/src/babel/transformation/templates/to-consumable-array.js +++ b/src/babel/transformation/templates/to-consumable-array.js @@ -1,5 +1,5 @@ (function (arr) { - if (Array.isArray(arr)) { + if (arr && arr.constructor === Array) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { diff --git a/src/babel/transformation/transformers/internal/validation.js b/src/babel/transformation/transformers/internal/validation.js index 87119f6380..c21b524294 100644 --- a/src/babel/transformation/transformers/internal/validation.js +++ b/src/babel/transformation/transformers/internal/validation.js @@ -1,6 +1,10 @@ import * as messages from "../../../messages"; import * as t from "../../../types"; +export var metadata = { + readOnly: true +}; + export function ForOfStatement(node, parent, scope, file) { var left = node.left; if (t.isVariableDeclaration(left)) { diff --git a/src/babel/traversal/index.js b/src/babel/traversal/index.js index fa68811939..0f0a5db68c 100644 --- a/src/babel/traversal/index.js +++ b/src/babel/traversal/index.js @@ -38,8 +38,9 @@ traverse.node = function (node, opts, scope, state, parentPath) { }; const CLEAR_KEYS = [ - "trailingComments", "leadingComments", "_declarations", "extendedRange", - "_paths", "tokens", "range", "start", "end", "loc", "raw" + "trailingComments", "leadingComments", "extendedRange", + "_declarations", "_scopeInfo" ,"_paths", + "tokens", "range", "start", "end", "loc", "raw" ]; function clearNode(node) { diff --git a/src/babel/traversal/path/index.js b/src/babel/traversal/path/index.js index 64fed848f0..40248f93c4 100644 --- a/src/babel/traversal/path/index.js +++ b/src/babel/traversal/path/index.js @@ -5,6 +5,7 @@ import isString from "lodash/lang/isString"; import traverse from "../index"; import includes from "lodash/collection/includes"; import assign from "lodash/object/assign"; +import extend from "lodash/object/extend"; import Scope from "../scope"; import * as t from "../../types"; @@ -158,7 +159,6 @@ export default class TraversalPath { } this.flatten(); - // TODO: duplicate internal path metadata across the new node paths } } @@ -210,15 +210,24 @@ export default class TraversalPath { return this.shouldStop; } - get(key) { - var node = this.node; - var container = node[key]; - if (Array.isArray(container)) { - return container.map((_, i) => { - return TraversalPath.get(this, this.context, node, container, i); - }); - } else { - return TraversalPath.get(this, this.context, node, node, key); + get(key: string): TraversalPath { + var parts = key.split("."); + if (parts.length === 1) { // "foo.bar" + var node = this.node; + var container = node[key]; + if (Array.isArray(container)) { + return container.map((_, i) => { + return TraversalPath.get(this, this.context, node, container, i); + }); + } else { + return TraversalPath.get(this, this.context, node, node, key); + } + } else { // "foo" + var path = this; + for (var i = 0; i > parts.length; i++) { + path = path.get(parts[i]); + } + return path; } } diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index 6c75615e70..ba3364b6a4 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -294,6 +294,7 @@ export default class Scope { } else if (i) { args.push(t.literal(i)); helperName = "sliced-to-array"; + if (this.file.isLoose("es6.forOf")) helperName += "-loose"; } return t.callExpression(file.addHelper(helperName), args); } @@ -400,14 +401,14 @@ export default class Scope { // - var info = path.getData("scopeInfo"); + var info = this.block._scopeInfo; if (info) return extend(this, info); - info = path.setData("scopeInfo", { + info = this.block._scopeInfo = { bindings: object(), globals: object(), uids: object() - }); + }; extend(this, info); diff --git a/src/babel/types/index.js b/src/babel/types/index.js index f1d8c6318a..cc93dbb9df 100644 --- a/src/babel/types/index.js +++ b/src/babel/types/index.js @@ -282,6 +282,7 @@ export function inheritsComments(child: Object, parent: Object): Object { export function inherits(child: Object, parent: Object): Object { child._declarations = parent._declarations; + child._scopeInfo = parent._scopeInfo; child.range = parent.range; child.start = parent.start; child.loc = parent.loc; diff --git a/src/babel/util.js b/src/babel/util.js index c61fef5ba9..61bccf1410 100644 --- a/src/babel/util.js +++ b/src/babel/util.js @@ -1,5 +1,6 @@ import "./patch"; +import escapeRegExp from "lodash/string/escapeRegExp"; import buildDebug from "debug/node"; import cloneDeep from "lodash/lang/cloneDeep"; import isBoolean from "lodash/lang/isBoolean"; @@ -43,7 +44,7 @@ export function list(val: string): Array { export function regexify(val: any): RegExp { if (!val) return new RegExp(/.^/); - if (Array.isArray(val)) val = val.join("|"); + if (Array.isArray(val)) val = new RegExp(val.map(escapeRegExp).join("|"), "i"); if (isString(val)) return minimatch.makeRe(val, { nocase: true }); if (isRegExp(val)) return val; throw new TypeError("illegal type for regexify"); diff --git a/test/fixtures/esnext/es6-arrow-functions/does-not-bind-this-from-standard-function.js b/test/fixtures/esnext/es6-arrow-functions/does-not-bind-this-from-standard-function.js deleted file mode 100644 index 6f3ffee93a..0000000000 --- a/test/fixtures/esnext/es6-arrow-functions/does-not-bind-this-from-standard-function.js +++ /dev/null @@ -1,5 +0,0 @@ -var dynamicThisGetter = () => function () { return this; }; -assert.equal( - '(' + dynamicThisGetter.toString() + ')', - '(function () {\n return function () {\n return this;\n };\n})' -); diff --git a/test/fixtures/transformation/es6-for-of-loose/identifier/expected.js b/test/fixtures/transformation/es6-for-of-loose/identifier/expected.js index cb83442b64..0d8a45e609 100644 --- a/test/fixtures/transformation/es6-for-of-loose/identifier/expected.js +++ b/test/fixtures/transformation/es6-for-of-loose/identifier/expected.js @@ -1,6 +1,6 @@ "use strict"; -for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { +for (var _iterator = arr, _isArray = _iterator && _iterator.constructor === Array, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { if (_isArray) { if (_i >= _iterator.length) break; i = _iterator[_i++]; diff --git a/test/fixtures/transformation/es6-for-of-loose/ignore-cases/expected.js b/test/fixtures/transformation/es6-for-of-loose/ignore-cases/expected.js index d7576bf4f7..58cd9b98e6 100644 --- a/test/fixtures/transformation/es6-for-of-loose/ignore-cases/expected.js +++ b/test/fixtures/transformation/es6-for-of-loose/ignore-cases/expected.js @@ -1,6 +1,6 @@ "use strict"; -for (var _iterator = foo, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { +for (var _iterator = foo, _isArray = _iterator && _iterator.constructor === Array, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { diff --git a/test/fixtures/transformation/es6-for-of-loose/let/expected.js b/test/fixtures/transformation/es6-for-of-loose/let/expected.js index 24b278f864..246b378924 100644 --- a/test/fixtures/transformation/es6-for-of-loose/let/expected.js +++ b/test/fixtures/transformation/es6-for-of-loose/let/expected.js @@ -1,6 +1,6 @@ "use strict"; -for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { +for (var _iterator = arr, _isArray = _iterator && _iterator.constructor === Array, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { diff --git a/test/fixtures/transformation/es6-for-of-loose/member-expression/expected.js b/test/fixtures/transformation/es6-for-of-loose/member-expression/expected.js index 10c85b30a2..cc864f5fe8 100644 --- a/test/fixtures/transformation/es6-for-of-loose/member-expression/expected.js +++ b/test/fixtures/transformation/es6-for-of-loose/member-expression/expected.js @@ -1,6 +1,6 @@ "use strict"; -for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { +for (var _iterator = arr, _isArray = _iterator && _iterator.constructor === Array, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { if (_isArray) { if (_i >= _iterator.length) break; obj.prop = _iterator[_i++]; diff --git a/test/fixtures/transformation/es6-for-of-loose/multiple/expected.js b/test/fixtures/transformation/es6-for-of-loose/multiple/expected.js index f3a251f396..fb5e478b26 100644 --- a/test/fixtures/transformation/es6-for-of-loose/multiple/expected.js +++ b/test/fixtures/transformation/es6-for-of-loose/multiple/expected.js @@ -1,6 +1,6 @@ "use strict"; -for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { +for (var _iterator = arr, _isArray = _iterator && _iterator.constructor === Array, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { @@ -15,7 +15,7 @@ for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator var i = _ref; } -for (var _iterator2 = numbers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { +for (var _iterator2 = numbers, _isArray2 = _iterator2 && _iterator2.constructor === Array, _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { var _ref2; if (_isArray2) { diff --git a/test/fixtures/transformation/es6-for-of-loose/var/expected.js b/test/fixtures/transformation/es6-for-of-loose/var/expected.js index 24b278f864..246b378924 100644 --- a/test/fixtures/transformation/es6-for-of-loose/var/expected.js +++ b/test/fixtures/transformation/es6-for-of-loose/var/expected.js @@ -1,6 +1,6 @@ "use strict"; -for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { +for (var _iterator = arr, _isArray = _iterator && _iterator.constructor === Array, _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { diff --git a/test/fixtures/transformation/es6-spread/arguments-array/expected.js b/test/fixtures/transformation/es6-spread/arguments-array/expected.js index 705f37c31e..18aecfa027 100644 --- a/test/fixtures/transformation/es6-spread/arguments-array/expected.js +++ b/test/fixtures/transformation/es6-spread/arguments-array/expected.js @@ -1,8 +1,7 @@ "use strict"; -var _slice = Array.prototype.slice; function foo() { - return bar([].concat(_slice.call(arguments))); + return bar([].concat(babelHelpers.slice.call(arguments))); } function bar(one, two, three) { diff --git a/test/fixtures/transformation/es6-spread/arguments-concat/expected.js b/test/fixtures/transformation/es6-spread/arguments-concat/expected.js index a95f66cf85..23468169cb 100644 --- a/test/fixtures/transformation/es6-spread/arguments-concat/expected.js +++ b/test/fixtures/transformation/es6-spread/arguments-concat/expected.js @@ -1,8 +1,7 @@ "use strict"; -var _slice = Array.prototype.slice; function foo() { - return bar.apply(undefined, ["test"].concat(_slice.call(arguments))); + return bar.apply(undefined, ["test"].concat(babelHelpers.slice.call(arguments))); } function bar(one, two, three) { diff --git a/test/fixtures/transformation/es6-spread/array-literal-first/expected.js b/test/fixtures/transformation/es6-spread/array-literal-first/expected.js index 4fe049cf69..65e76aebc6 100644 --- a/test/fixtures/transformation/es6-spread/array-literal-first/expected.js +++ b/test/fixtures/transformation/es6-spread/array-literal-first/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -var lyrics = [].concat(_toConsumableArray(parts), ["head", "and", "toes"]); +var lyrics = [].concat(babelHelpers.toConsumableArray(parts), ["head", "and", "toes"]); diff --git a/test/fixtures/transformation/es6-spread/array-literal-middle/expected.js b/test/fixtures/transformation/es6-spread/array-literal-middle/expected.js index a4a19d29d0..91292cb698 100644 --- a/test/fixtures/transformation/es6-spread/array-literal-middle/expected.js +++ b/test/fixtures/transformation/es6-spread/array-literal-middle/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -var a = [b].concat(_toConsumableArray(c), [d]); +var a = [b].concat(babelHelpers.toConsumableArray(c), [d]); diff --git a/test/fixtures/transformation/es6-spread/array-literal-multiple/expected.js b/test/fixtures/transformation/es6-spread/array-literal-multiple/expected.js index 8190d877aa..a9e349d03b 100644 --- a/test/fixtures/transformation/es6-spread/array-literal-multiple/expected.js +++ b/test/fixtures/transformation/es6-spread/array-literal-multiple/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -var a = [b].concat(_toConsumableArray(c), [d, e], _toConsumableArray(f)); +var a = [b].concat(babelHelpers.toConsumableArray(c), [d, e], babelHelpers.toConsumableArray(f)); diff --git a/test/fixtures/transformation/es6-spread/array-literals/expected.js b/test/fixtures/transformation/es6-spread/array-literals/expected.js index 5881ce581e..436c91026b 100644 --- a/test/fixtures/transformation/es6-spread/array-literals/expected.js +++ b/test/fixtures/transformation/es6-spread/array-literals/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -var lyrics = ["head", "and", "toes"].concat(_toConsumableArray(parts)); +var lyrics = ["head", "and", "toes"].concat(babelHelpers.toConsumableArray(parts)); diff --git a/test/fixtures/transformation/es6-spread/contexted-computed-method-call-multiple-args/expected.js b/test/fixtures/transformation/es6-spread/contexted-computed-method-call-multiple-args/expected.js index 2acacbf97d..93e7396960 100644 --- a/test/fixtures/transformation/es6-spread/contexted-computed-method-call-multiple-args/expected.js +++ b/test/fixtures/transformation/es6-spread/contexted-computed-method-call-multiple-args/expected.js @@ -2,6 +2,4 @@ var _obj; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -(_obj = obj)[method].apply(_obj, [foo, bar].concat(_toConsumableArray(args))); +(_obj = obj)[method].apply(_obj, [foo, bar].concat(babelHelpers.toConsumableArray(args))); diff --git a/test/fixtures/transformation/es6-spread/contexted-computed-method-call-single-arg/expected.js b/test/fixtures/transformation/es6-spread/contexted-computed-method-call-single-arg/expected.js index 90d4042576..e1a10318ec 100644 --- a/test/fixtures/transformation/es6-spread/contexted-computed-method-call-single-arg/expected.js +++ b/test/fixtures/transformation/es6-spread/contexted-computed-method-call-single-arg/expected.js @@ -2,6 +2,4 @@ var _obj; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -(_obj = obj)[method].apply(_obj, _toConsumableArray(args)); +(_obj = obj)[method].apply(_obj, babelHelpers.toConsumableArray(args)); diff --git a/test/fixtures/transformation/es6-spread/contexted-method-call-multiple-args/expected.js b/test/fixtures/transformation/es6-spread/contexted-method-call-multiple-args/expected.js index 8918047bf1..97f2cdfdf0 100644 --- a/test/fixtures/transformation/es6-spread/contexted-method-call-multiple-args/expected.js +++ b/test/fixtures/transformation/es6-spread/contexted-method-call-multiple-args/expected.js @@ -2,7 +2,5 @@ var _foob, _foob$test; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -(_foob = foob).add.apply(_foob, [foo, bar].concat(_toConsumableArray(numbers))); -(_foob$test = foob.test).add.apply(_foob$test, [foo, bar].concat(_toConsumableArray(numbers))); +(_foob = foob).add.apply(_foob, [foo, bar].concat(babelHelpers.toConsumableArray(numbers))); +(_foob$test = foob.test).add.apply(_foob$test, [foo, bar].concat(babelHelpers.toConsumableArray(numbers))); diff --git a/test/fixtures/transformation/es6-spread/contexted-method-call-single-arg/expected.js b/test/fixtures/transformation/es6-spread/contexted-method-call-single-arg/expected.js index 68e7049991..868a092240 100644 --- a/test/fixtures/transformation/es6-spread/contexted-method-call-single-arg/expected.js +++ b/test/fixtures/transformation/es6-spread/contexted-method-call-single-arg/expected.js @@ -2,7 +2,5 @@ var _foob, _foob$test; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -(_foob = foob).add.apply(_foob, _toConsumableArray(numbers)); -(_foob$test = foob.test).add.apply(_foob$test, _toConsumableArray(numbers)); +(_foob = foob).add.apply(_foob, babelHelpers.toConsumableArray(numbers)); +(_foob$test = foob.test).add.apply(_foob$test, babelHelpers.toConsumableArray(numbers)); diff --git a/test/fixtures/transformation/es6-spread/method-call-first/expected.js b/test/fixtures/transformation/es6-spread/method-call-first/expected.js index 958db15bb1..b21bb56b0b 100644 --- a/test/fixtures/transformation/es6-spread/method-call-first/expected.js +++ b/test/fixtures/transformation/es6-spread/method-call-first/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -add.apply(undefined, _toConsumableArray(numbers).concat([foo, bar])); +add.apply(undefined, babelHelpers.toConsumableArray(numbers).concat([foo, bar])); diff --git a/test/fixtures/transformation/es6-spread/method-call-middle/expected.js b/test/fixtures/transformation/es6-spread/method-call-middle/expected.js index 3ad75de3cc..aa58d4b763 100644 --- a/test/fixtures/transformation/es6-spread/method-call-middle/expected.js +++ b/test/fixtures/transformation/es6-spread/method-call-middle/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -add.apply(undefined, [foo].concat(_toConsumableArray(numbers), [bar])); +add.apply(undefined, [foo].concat(babelHelpers.toConsumableArray(numbers), [bar])); diff --git a/test/fixtures/transformation/es6-spread/method-call-multiple-args/expected.js b/test/fixtures/transformation/es6-spread/method-call-multiple-args/expected.js index 1e2cedd9c4..b05198cb1f 100644 --- a/test/fixtures/transformation/es6-spread/method-call-multiple-args/expected.js +++ b/test/fixtures/transformation/es6-spread/method-call-multiple-args/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -add.apply(undefined, [foo, bar].concat(_toConsumableArray(numbers))); +add.apply(undefined, [foo, bar].concat(babelHelpers.toConsumableArray(numbers))); diff --git a/test/fixtures/transformation/es6-spread/method-call-multiple/expected.js b/test/fixtures/transformation/es6-spread/method-call-multiple/expected.js index c07763c6b3..efbcb25bb6 100644 --- a/test/fixtures/transformation/es6-spread/method-call-multiple/expected.js +++ b/test/fixtures/transformation/es6-spread/method-call-multiple/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -add.apply(undefined, [foo].concat(_toConsumableArray(numbers), [bar, what], _toConsumableArray(test))); +add.apply(undefined, [foo].concat(babelHelpers.toConsumableArray(numbers), [bar, what], babelHelpers.toConsumableArray(test))); diff --git a/test/fixtures/transformation/es6-spread/method-call-single-arg/expected.js b/test/fixtures/transformation/es6-spread/method-call-single-arg/expected.js index f697e3b8f5..3b817b4f15 100644 --- a/test/fixtures/transformation/es6-spread/method-call-single-arg/expected.js +++ b/test/fixtures/transformation/es6-spread/method-call-single-arg/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -add.apply(undefined, _toConsumableArray(numbers)); +add.apply(undefined, babelHelpers.toConsumableArray(numbers)); diff --git a/test/fixtures/transformation/es6-spread/new-expression/expected.js b/test/fixtures/transformation/es6-spread/new-expression/expected.js index de0426cd6f..6f963d42dd 100644 --- a/test/fixtures/transformation/es6-spread/new-expression/expected.js +++ b/test/fixtures/transformation/es6-spread/new-expression/expected.js @@ -1,8 +1,4 @@ "use strict"; -var _applyConstructor = function (Constructor, args) { var instance = Object.create(Constructor.prototype); var result = Constructor.apply(instance, args); return result != null && (typeof result == "object" || typeof result == "function") ? result : instance; }; - -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -_applyConstructor(Numbers, _toConsumableArray(nums)); -_applyConstructor(Numbers, [1].concat(_toConsumableArray(nums))); +babelHelpers.applyConstructor(Numbers, babelHelpers.toConsumableArray(nums)); +babelHelpers.applyConstructor(Numbers, [1].concat(babelHelpers.toConsumableArray(nums))); diff --git a/test/fixtures/transformation/es6-spread/options.json b/test/fixtures/transformation/es6-spread/options.json index b8b90ecb11..02c3a96413 100644 --- a/test/fixtures/transformation/es6-spread/options.json +++ b/test/fixtures/transformation/es6-spread/options.json @@ -1,3 +1,4 @@ -{ - "blacklist": ["es6.tailCall"] -} +{ + "externalHelpers": true, + "blacklist": ["es6.tailCall"] +} diff --git a/test/fixtures/transformation/es6-spread/single/expected.js b/test/fixtures/transformation/es6-spread/single/expected.js index 74a812d890..68249fd331 100644 --- a/test/fixtures/transformation/es6-spread/single/expected.js +++ b/test/fixtures/transformation/es6-spread/single/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; - -[].concat(_toConsumableArray(foo)); +[].concat(babelHelpers.toConsumableArray(foo)); diff --git a/test/util.js b/test/util.js index 2562750dc2..88276ffbc3 100644 --- a/test/util.js +++ b/test/util.js @@ -78,8 +78,8 @@ suite("util", function () { assert.deepEqual(util.regexify(false), /.^/); assert.deepEqual(util.regexify(null), /.^/); assert.deepEqual(util.regexify(""), /.^/); - assert.deepEqual(util.regexify(["foo", "bar"]), /foo|bar/); - assert.deepEqual(util.regexify("foobar"), /foobar/); + assert.deepEqual(util.regexify(["foo", "bar"]), /foo|bar/i); + assert.deepEqual(util.regexify("foobar"), /^(?:(?=.)foobar)$/i); assert.deepEqual(util.regexify(/foobar/), /foobar/); assert.throws(function () { diff --git a/vendor/acorn/acorn.js b/vendor/acorn/acorn.js index 68b94cf405..77432428a9 100644 --- a/vendor/acorn/acorn.js +++ b/vendor/acorn/acorn.js @@ -243,6 +243,7 @@ this.label = label; this.keyword = conf.keyword; this.beforeExpr = !!conf.beforeExpr; + this.startsExpr = !!conf.startsExpr; this.rightAssociative = !!conf.rightAssociative; this.isLoop = !!conf.isLoop; this.isAssign = !!conf.isAssign; @@ -255,21 +256,21 @@ function binop(name, prec) { return new TokenType(name, {beforeExpr: true, binop: prec}); } - var beforeExpr = {beforeExpr: true}; + var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};; var tt = exports.tokTypes = { - num: new TokenType("num"), - regexp: new TokenType("regexp"), - string: new TokenType("string"), - name: new TokenType("name"), + num: new TokenType("num", startsExpr), + regexp: new TokenType("regexp", startsExpr), + string: new TokenType("string", startsExpr), + name: new TokenType("name", startsExpr), eof: new TokenType("eof"), // Punctuation token types. - bracketL: new TokenType("[", beforeExpr), + bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}), bracketR: new TokenType("]"), - braceL: new TokenType("{", beforeExpr), + braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}), braceR: new TokenType("}"), - parenL: new TokenType("(", beforeExpr), + parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}), parenR: new TokenType(")"), comma: new TokenType(",", beforeExpr), semi: new TokenType(";", beforeExpr), @@ -279,8 +280,8 @@ arrow: new TokenType("=>", beforeExpr), template: new TokenType("template"), ellipsis: new TokenType("...", beforeExpr), - backQuote: new TokenType("`"), - dollarBraceL: new TokenType("${", beforeExpr), + backQuote: new TokenType("`", startsExpr), + dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}), // Operators. These carry several kinds of properties to help the // parser use them properly (the presence of these properties is @@ -298,8 +299,8 @@ eq: new TokenType("=", {beforeExpr: true, isAssign: true}), assign: new TokenType("_=", {beforeExpr: true, isAssign: true}), - incDec: new TokenType("++/--", {prefix: true, postfix: true}), - prefix: new TokenType("prefix", {beforeExpr: true, prefix: true}), + incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}), + prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}), logicalOR: binop("||", 1), logicalAND: binop("&&", 2), bitwiseOR: binop("|", 3), @@ -308,7 +309,7 @@ equality: binop("==/!=", 6), relational: binop("", 7), bitShift: binop("<>", 8), - plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true}), + plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}), modulo: binop("%", 10), star: binop("*", 10), slash: binop("/", 10), @@ -347,22 +348,22 @@ kw("const"); kw("while", {isLoop: true}); kw("with"); - kw("new", beforeExpr); - kw("this"); - kw("super"); + kw("new", {beforeExpr: true, startsExpr: true}); + kw("this", startsExpr); + kw("super", startsExpr); kw("class"); kw("extends", beforeExpr); kw("export"); kw("import"); - kw("yield", beforeExpr); - kw("null"); - kw("true"); - kw("false"); + kw("yield", {beforeExpr: true, startsExpr: true}); + kw("null", startsExpr); + kw("true", startsExpr); + kw("false", startsExpr); kw("in", {beforeExpr: true, binop: 7}); kw("instanceof", {beforeExpr: true, binop: 7}); - kw("typeof", {beforeExpr: true, prefix: true}); - kw("void", {beforeExpr: true, prefix: true}); - kw("delete", {beforeExpr: true, prefix: true}); + kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}); + kw("void", {beforeExpr: true, prefix: true, startsExpr: true}); + kw("delete", {beforeExpr: true, prefix: true, startsExpr: true}); // This is a trick taken from Esprima. It turns out that, on // non-Chrome browsers, to check whether a string is in a set, a @@ -1125,13 +1126,15 @@ if (this.options.ecmaVersion >= 6) validFlags = /^[gmsiyu]*$/; if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag"); if (mods.indexOf('u') >= 0 && !regexpUnicodeSupport) { - // Replace each astral symbol and every Unicode code point - // escape sequence that represents such a symbol with a single - // ASCII symbol to avoid throwing on regular expressions that + // Replace each astral symbol and every Unicode escape sequence that + // possibly represents an astral symbol or a paired surrogate with a + // single ASCII symbol to avoid throwing on regular expressions that // are only valid in combination with the `/u` flag. - tmp = tmp - .replace(/\\u\{([0-9a-fA-F]+)\}/g, "x") - .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x"); + // Note: replacing with the ASCII symbol `x` might cause false + // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a + // perfectly valid pattern that is equivalent to `[a-b]`, but it would + // be replaced by `[x-b]` which throws an error. + tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]+)\}|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x") } } // Detect invalid regular expressions. @@ -1604,24 +1607,23 @@ // Convert list of expression atoms to binding list. pp.toAssignableList = function(exprList, isBinding) { - if (exprList.length) { - for (var i = 0; i < exprList.length - 1; i++) { - this.toAssignable(exprList[i], isBinding); - } - var last = exprList[exprList.length - 1]; - switch (last.type) { - case "RestElement": - break; - case "SpreadElement": - last.type = "RestElement"; - var arg = last.argument; - this.toAssignable(arg, isBinding); - if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") - this.unexpected(arg.start); - break; - default: - this.toAssignable(last, isBinding); - } + var end = exprList.length; + if (end) { + var last = exprList[end - 1]; + if (last && last.type == "RestElement") { + --end; + } else if (last && last.type == "SpreadElement") { + last.type = "RestElement"; + var arg = last.argument; + this.toAssignable(arg, isBinding); + if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") + this.unexpected(arg.start); + --end; + } + } + for (var i = 0; i < end; i++) { + var elt = exprList[i]; + if (elt) this.toAssignable(elt, isBinding); } return exprList; }; @@ -2193,6 +2195,8 @@ decl.init = this.parseMaybeAssign(noIn); } else if (kind === tt._const && !(this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) { this.unexpected(); + } else if (decl.id.type != "Identifier") { + this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value"); } else { decl.init = null; } @@ -2634,12 +2638,10 @@ if (this.options.ecmaVersion >= 6) { prop.method = false; prop.shorthand = false; - if (isPattern || refShorthandDefaultPos) { + if (isPattern || refShorthandDefaultPos) start = this.currentPos(); - } - if (!isPattern) { + if (!isPattern) isGenerator = this.eat(tt.star); - } } if (this.options.features["es7.asyncFunctions"] && this.isContextual("async")) { if (isGenerator || isPattern) this.unexpected(); @@ -2680,6 +2682,10 @@ } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { prop.kind = "init"; if (isPattern) { + if (this.isKeyword(prop.key.name) || + (this.strict && (isStrictBadIdWord(prop.key.name) || isStrictReservedWord(prop.key.name))) || + (!this.options.allowReserved && this.isReservedWord(prop.key.name))) + this.raise(prop.key.start, "Binding " + prop.key.name); prop.value = this.parseMaybeDefault(start, prop.key); } else if (this.type === tt.eq && refShorthandDefaultPos) { if (!refShorthandDefaultPos.start) @@ -3040,7 +3046,7 @@ pp.parseYield = function() { var node = this.startNode(); this.next(); - if (this.type == tt.semi || this.canInsertSemicolon()) { + if (this.type == tt.semi || this.canInsertSemicolon() || (this.type != tt.star && !this.type.startsExpr)) { node.delegate = false; node.argument = null; } else { diff --git a/vendor/acorn/test/tests-harmony.js b/vendor/acorn/test/tests-harmony.js index 72154470c7..9399254a06 100644 --- a/vendor/acorn/test/tests-harmony.js +++ b/vendor/acorn/test/tests-harmony.js @@ -5989,6 +5989,53 @@ test("var x = { *test () { yield *v } };", { locations: true }); +test("function* foo() { console.log(yield); }", { + body: [ + { + id: { + name: "foo", + type: "Identifier", + }, + generator: true, + expression: false, + params: [], + body: { + body: [ + { + expression: { + callee: { + object: { + name: "console", + type: "Identifier", + }, + property: { + name: "log", + type: "Identifier", + }, + computed: false, + type: "MemberExpression", + }, + arguments: [ + { + delegate: false, + argument: null, + type: "YieldExpression", + } + ], + type: "CallExpression", + }, + type: "ExpressionStatement", + } + ], + type: "BlockStatement", + }, + type: "FunctionDeclaration", + } + ], + sourceType: "script", + type: "Program" +}, {ecmaVersion: 6}) + test("function* t() {}", { type: "Program", body: [{ @@ -13814,6 +13861,34 @@ test("/[a-z]/u", { ecmaVersion: 6 }); +test("/[\\uD834\\uDF06-\\uD834\\uDF08a-z]/u", { + type: "Program", + body: [ + { + type: "ExpressionStatement", + expression: { + type: "Literal", + regex: { + pattern: "[\\uD834\\uDF06-\\uD834\\uDF08a-z]", + flags: "u" + }, + loc: { + start: { + line: 1, + column: 0 + }, + end: { + line: 1, + column: 33 + } + } + } + } + ] +}, { + locations: true, + ecmaVersion: 6 +}); test("do {} while (false) foo();", { type: "Program", @@ -15419,6 +15494,36 @@ test("let {x} = y", { "end": 11 }, {ecmaVersion: 6}) +test("[x,,] = 1", { + type: "Program", + body: [ + { + type: "ExpressionStatement", + expression: { + type: "AssignmentExpression", + operator: "=", + left: { + type: "ArrayPattern", + elements: [ + { + type: "Identifier", + name: "x" + }, + null + ] + }, + right: { + type: "Literal", + value: 1, + raw: "1" + } + } + } + ] +}, {ecmaVersion: 6}); + +testFail("let [x]", "Complex binding patterns require an initialization value (1:7)", {ecmaVersion: 6}) +testFail("var [x]", "Complex binding patterns require an initialization value (1:7)", {ecmaVersion: 6}) testFail("var _𖫵 = 11;", "Unexpected character '𖫵' (1:5)", {ecmaVersion: 6}); testFail("var 𫠞_ = 12;", "Unexpected character '𫠞' (1:4)", {ecmaVersion: 6}); testFail("var 𫠝_ = 10;", "Unexpected character '𫠝' (1:4)", {ecmaVersion: 5}); @@ -15431,3 +15536,5 @@ testFail("'use strict'; [...eval] = arr", "Assigning to eval in strict mode (1:1 testFail("'use strict'; ({eval = defValue} = obj)", "Assigning to eval in strict mode (1:16)", {ecmaVersion: 6}); testFail("[...eval] = arr", "Assigning to eval in strict mode (1:4)", {ecmaVersion: 6, sourceType: "module"}); + +testFail("function* y({yield}) {}", "Binding yield (1:13)", {ecmaVersion: 6});