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

Commit

Permalink
Implement parsing use @babel/core#parse
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Nov 7, 2018
1 parent 2a0cb9d commit f8cb746
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
77 changes: 39 additions & 38 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use strict";

const babylonToEspree = require("./babylon-to-espree");
const parse = require("@babel/parser").parse;
const traverse = require("@babel/core").traverse;
const { parseSync: parse, traverse } = require("@babel/core");
const tt = require("@babel/parser").tokTypes;

module.exports = function(code, options) {
Expand All @@ -11,42 +10,44 @@ module.exports = function(code, options) {

const opts = {
sourceType: options.sourceType,
allowImportExportEverywhere: options.allowImportExportEverywhere, // consistent with espree
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
ranges: true,
tokens: true,
plugins: [
["flow", { all: true }],
"jsx",
"estree",
"asyncFunctions",
"asyncGenerators",
"classConstructorCall",
"classProperties",
legacyDecorators
? "decorators-legacy"
: ["decorators", { decoratorsBeforeExport: false }],
"doExpressions",
"exponentiationOperator",
"exportDefaultFrom",
"exportNamespaceFrom",
"functionBind",
"functionSent",
"objectRestSpread",
"trailingFunctionCommas",
"dynamicImport",
"numericSeparator",
"optionalChaining",
"importMeta",
"classPrivateProperties",
"bigInt",
"optionalCatchBinding",
"throwExpressions",
["pipelineOperator", { proposal: "minimal" }],
"nullishCoalescingOperator",
"logicalAssignment",
],
parserOpts: {
allowImportExportEverywhere: options.allowImportExportEverywhere, // consistent with espree
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
ranges: true,
tokens: true,
plugins: [
["flow", { all: true }],
"jsx",
"estree",
"asyncFunctions",
"asyncGenerators",
"classConstructorCall",
"classProperties",
legacyDecorators
? "decorators-legacy"
: ["decorators", { decoratorsBeforeExport: false }],
"doExpressions",
"exponentiationOperator",
"exportDefaultFrom",
"exportNamespaceFrom",
"functionBind",
"functionSent",
"objectRestSpread",
"trailingFunctionCommas",
"dynamicImport",
"numericSeparator",
"optionalChaining",
"importMeta",
"classPrivateProperties",
"bigInt",
"optionalCatchBinding",
"throwExpressions",
["pipelineOperator", { proposal: "minimal" }],
"nullishCoalescingOperator",
"logicalAssignment",
],
},
};

let ast;
Expand Down
2 changes: 1 addition & 1 deletion test/babel-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ describe("Public API", () => {
it("exports a parseNoPatch function", () => {
assertImplementsAST(
espree.parse("foo"),
babelEslint.parseNoPatch("foo", {})
babelEslint.parseNoPatch("foo", { sourceType: "script" })
);
});
});

0 comments on commit f8cb746

Please sign in to comment.