Skip to content

Commit

Permalink
[FEATURE] Support ES2021 language features
Browse files Browse the repository at this point in the history
By upgrading espree to the latest version, ES2021 language features
are now supported.
  • Loading branch information
matz3 committed Jan 25, 2022
1 parent 50e2c7c commit e749b6a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 100 deletions.
7 changes: 7 additions & 0 deletions lib/lbt/analyzer/JSModuleAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const EnrichedVisitorKeys = (function() {
BreakStatement: [],
CallExpression: [], // special handling
CatchClause: ["param", "body"],
ChainExpression: [],
ClassBody: [],
ClassDeclaration: [],
ClassExpression: [],
Expand Down Expand Up @@ -125,15 +126,18 @@ const EnrichedVisitorKeys = (function() {
* All properties in an object pattern are executed.
*/
ObjectPattern: [], // properties
// PrivateIdentifier: [], // will come with ES2022
Program: [],
Property: [],
// PropertyDefinition: [], // will come with ES2022
/*
* argument of the rest element is always executed under the same condition as the rest element itself
*/
RestElement: [], // argument
ReturnStatement: [],
SequenceExpression: [],
SpreadElement: [], // the argument of the spread operator always needs to be evaluated - argument
// StaticBlock: [], // will come with ES2022
Super: [],
SwitchStatement: [],
SwitchCase: ["test", "consequent"], // test and consequent are executed only conditionally
Expand Down Expand Up @@ -174,6 +178,9 @@ const EnrichedVisitorKeys = (function() {
// Check if the visitor-key exists in the available Syntax because
// the list of visitor-keys does not match the available Syntax.
if (!Syntax[type]) {
// Deprecated / removed:
// ExperimentalRestProperty
// ExperimentalSpreadProperty
return;
}
// Ignore JSX visitor-keys because they aren't used.
Expand Down
2 changes: 1 addition & 1 deletion lib/lbt/utils/parseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function parseJS(code, userOptions = {}) {
// allowed options and their defaults
const options = {
comment: false,
ecmaVersion: 2020,
ecmaVersion: 2021,
range: false,
sourceType: "script",
};
Expand Down
113 changes: 15 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"cheerio": "1.0.0-rc.9",
"escape-unicode": "^0.2.0",
"escope": "^3.6.0",
"espree": "^6.2.1",
"espree": "^9.3.0",
"globby": "^11.1.0",
"graceful-fs": "^4.2.9",
"jsdoc": "^3.6.7",
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/lbt/modules/es6-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ sap.ui.define([
await Promise.resolve();
};

// chain expression
if (m1?.foo?.bar) {
sap.ui.require(["conditional/module4"]);
}

});
1 change: 1 addition & 0 deletions test/lib/lbt/analyzer/JSModuleAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ test("ES6 Syntax", (t) => {
"conditional/module1.js",
"conditional/module2.js",
"conditional/module3.js",
"conditional/module4.js",
"static/module1.js",
"static/module2.js",
"static/module3.js",
Expand Down
6 changes: 6 additions & 0 deletions test/lib/lbt/utils/parseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ test("successful parse step", (t) => {
t.true(ast != null && typeof ast === "object");
t.is(ast.type, "Program");
});

test("successful parse step (ES2021 features)", (t) => {
const ast = parseJS("const x = 1_000_000_000;"); // numeric separators
t.true(ast != null && typeof ast === "object");
t.is(ast.type, "Program");
});

0 comments on commit e749b6a

Please sign in to comment.