diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-01-31 08:36:48 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-02-08 15:34:10 +0100 |
commit | 582c12260ed99ebe7710894c2dab29435b1bebdc (patch) | |
tree | f5168c77fd86c471951f9a68ac9cb0cfb8812003 /lib | |
parent | 39171d755d3e81f03ac0fd716cd80c2e20882fb6 (diff) | |
download | android-node-v8-582c12260ed99ebe7710894c2dab29435b1bebdc.tar.gz android-node-v8-582c12260ed99ebe7710894c2dab29435b1bebdc.tar.bz2 android-node-v8-582c12260ed99ebe7710894c2dab29435b1bebdc.zip |
deps: update acorn to 6.0.7
acorn and acorn-walk are now published as two different packages. Put
them both in subdirectories of `deps/acorn`.
Adapt the REPL's recoverable error detection to use the new API for
extending acorn parsers.
PR-URL: https://github.com/nodejs/node/pull/25844
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/assert.js | 4 | ||||
-rw-r--r-- | lib/internal/repl/await.js | 4 | ||||
-rw-r--r-- | lib/internal/repl/recoverable.js | 31 | ||||
-rw-r--r-- | lib/repl.js | 2 |
4 files changed, 18 insertions, 23 deletions
diff --git a/lib/assert.js b/lib/assert.js index a37329caf2..013ae6e674 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -200,8 +200,8 @@ function getCode(fd, line, column) { function parseCode(code, offset) { // Lazy load acorn. if (parseExpressionAt === undefined) { - ({ parseExpressionAt } = require('internal/deps/acorn/dist/acorn')); - ({ findNodeAround } = require('internal/deps/acorn/dist/walk')); + ({ parseExpressionAt } = require('internal/deps/acorn/acorn/dist/acorn')); + ({ findNodeAround } = require('internal/deps/acorn/acorn-walk/dist/walk')); } let node; let start = 0; diff --git a/lib/internal/repl/await.js b/lib/internal/repl/await.js index 2f3e754b5d..bcc94ef186 100644 --- a/lib/internal/repl/await.js +++ b/lib/internal/repl/await.js @@ -1,7 +1,7 @@ 'use strict'; -const acorn = require('internal/deps/acorn/dist/acorn'); -const walk = require('internal/deps/acorn/dist/walk'); +const acorn = require('internal/deps/acorn/acorn/dist/acorn'); +const walk = require('internal/deps/acorn/acorn-walk/dist/walk'); const noop = () => {}; const visitorsWithoutAncestors = { diff --git a/lib/internal/repl/recoverable.js b/lib/internal/repl/recoverable.js index 2c31db9faf..bb5af0ec22 100644 --- a/lib/internal/repl/recoverable.js +++ b/lib/internal/repl/recoverable.js @@ -1,7 +1,7 @@ 'use strict'; -const acorn = require('internal/deps/acorn/dist/acorn'); -const { tokTypes: tt } = acorn; +const acorn = require('internal/deps/acorn/acorn/dist/acorn'); +const { tokTypes: tt, Parser: AcornParser } = acorn; // If the error is that we've unexpectedly ended the input, // then let the user try to recover by adding more input. @@ -26,17 +26,13 @@ function isRecoverableError(e, code) { // change these messages in the future, this will lead to a test // failure, indicating that this code needs to be updated. // - acorn.plugins.replRecoverable = (parser) => { - parser.extend('nextToken', (nextToken) => { - return function() { - Reflect.apply(nextToken, this, []); - + const RecoverableParser = AcornParser.extend((Parser) => { + return class extends Parser { + nextToken() { + super.nextToken(); if (this.type === tt.eof) recoverable = true; - }; - }); - - parser.extend('raise', (raise) => { - return function(pos, message) { + } + raise(pos, message) { switch (message) { case 'Unterminated template': case 'Unterminated comment': @@ -48,11 +44,10 @@ function isRecoverableError(e, code) { // See https://www.ecma-international.org/ecma-262/#sec-line-terminators recoverable = /\\(?:\r\n?|\n|\u2028|\u2029)$/.test(token); } - - Reflect.apply(raise, this, [pos, message]); - }; - }); - }; + super.raise(pos, message); + } + }; + }); // For similar reasons as `defaultEval`, wrap expressions starting with a // curly brace with parenthesis. Note: only the open parenthesis is added @@ -63,7 +58,7 @@ function isRecoverableError(e, code) { // Try to parse the code with acorn. If the parse fails, ignore the acorn // error and return the recoverable status. try { - acorn.parse(code, { plugins: { replRecoverable: true }, ecmaVersion: 10 }); + RecoverableParser.parse(code, { ecmaVersion: 10 }); // Odd case: the underlying JS engine (V8, Chakra) rejected this input // but Acorn detected no issue. Presume that additional text won't diff --git a/lib/repl.js b/lib/repl.js index 2568016948..f1b269b801 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -50,7 +50,7 @@ const { const { isIdentifierStart, isIdentifierChar -} = require('internal/deps/acorn/dist/acorn'); +} = require('internal/deps/acorn/acorn/dist/acorn'); const internalUtil = require('internal/util'); const util = require('util'); const Stream = require('stream'); |