assert: lazy load acorn

This makes sure acorn is only loaded in case it is necessary.

PR-URL: https://github.com/nodejs/node/pull/19863
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-04-07 14:38:27 +02:00
parent 252eb2deb2
commit 9c06770443
No known key found for this signature in database
GPG key ID: F07496B3EB3C1762

View file

@ -33,7 +33,6 @@ const {
}
} = require('internal/errors');
const { openSync, closeSync, readSync } = require('fs');
const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn');
const { inspect } = require('util');
const { EOL } = require('os');
const { NativeModule } = require('internal/bootstrap/loaders');
@ -173,6 +172,8 @@ function getErrMessage(call) {
fd = openSync(filename, 'r', 0o666);
const buffers = getBuffer(fd, line);
const code = Buffer.concat(buffers).toString('utf8');
// Lazy load acorn.
const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn');
const nodes = parseExpressionAt(code, column);
// Node type should be "CallExpression" and some times
// "SequenceExpression".