Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Remove tolerantParse workaround from parser.js.
Browse files Browse the repository at this point in the history
Now that @babel/parser@7.5.0 is out, we no longer need to simulate the
effect of babel/babel#9864.

See also benjamn/reify#230.
  • Loading branch information
benjamn committed Jul 4, 2019
1 parent 6e975ac commit 0c1bc32
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions parser.js
@@ -1,30 +1,10 @@
"use strict";

const babelParser = require("@babel/parser");
const babelParserVersion = require("@babel/parser/package.json").version;
const defaultParserOptions = require("reify/lib/parsers/babel.js").options;

function parse(code, parserOptions) {
return babelParser.parse(code, parserOptions || defaultParserOptions);
}

function tolerantParse(code, parserOptions) {
const arrayFrom = Array.from;
// There is only one use of Array.from in the @babel/parser@7.4.x code,
// Array.from(this.scope.undefinedExports), which determines whether the
// parser complains prematurely about exporting identifiers that were
// not declared in the current module scope. By returning an empty array
// when the source argument is a Map, we can effectively disable that
// error behavior, until https://github.com/babel/babel/pull/9864 is
// released in @babel/parser@7.5.0.
Array.from = function (source) {
return source instanceof Map ? [] : arrayFrom.apply(this, arguments);
};
try {
return parse(code, parserOptions);
} finally {
Array.from = arrayFrom;
}
}

exports.parse = babelParserVersion.startsWith("7.4.") ? tolerantParse : parse;
exports.parse = parse;

0 comments on commit 0c1bc32

Please sign in to comment.