From c0ab2a141b885f260b9fff53245e2d9eb4310d13 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 24 Apr 2019 23:54:42 +0200 Subject: [PATCH] assert: use new language features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds new language features to acorn. Otherwise BigInt and other input would not be parsed correct and would not result in nice error messages when using simple assert. PR-URL: https://github.com/nodejs/node/pull/27400 Refs: https://github.com/nodejs/node/issues/27391 Refs: https://github.com/nodejs/node/issues/25835 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- lib/assert.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/assert.js b/lib/assert.js index 376f4b732001bc..ffa71bfad8d412 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -203,8 +203,27 @@ function getCode(fd, line, column) { function parseCode(code, offset) { // Lazy load acorn. if (parseExpressionAt === undefined) { - ({ parseExpressionAt } = require('internal/deps/acorn/acorn/dist/acorn')); + const acorn = require('internal/deps/acorn/acorn/dist/acorn'); + const privateMethods = + require('internal/deps/acorn-plugins/acorn-private-methods/index'); + const bigInt = require('internal/deps/acorn-plugins/acorn-bigint/index'); + const classFields = + require('internal/deps/acorn-plugins/acorn-class-fields/index'); + const numericSeparator = + require('internal/deps/acorn-plugins/acorn-numeric-separator/index'); + const staticClassFeatures = + require('internal/deps/acorn-plugins/acorn-static-class-features/index'); + ({ findNodeAround } = require('internal/deps/acorn/acorn-walk/dist/walk')); + + const Parser = acorn.Parser.extend( + privateMethods, + bigInt, + classFields, + numericSeparator, + staticClassFeatures + ); + parseExpressionAt = Parser.parseExpressionAt.bind(Parser); } let node; let start = 0;