Merge branch 'master' into feat-optional-chaining
This commit is contained in:
@@ -459,6 +459,10 @@ export default class ExpressionParser extends LValParser {
|
||||
return this.finishNode(node, "Super");
|
||||
|
||||
case tt._import:
|
||||
if (this.hasPlugin("importMeta") && this.lookahead().type === tt.dot) {
|
||||
return this.parseImportMetaProperty();
|
||||
}
|
||||
|
||||
if (!this.hasPlugin("dynamicImport")) this.unexpected();
|
||||
|
||||
node = this.startNode();
|
||||
@@ -620,12 +624,22 @@ export default class ExpressionParser extends LValParser {
|
||||
node.property = this.parseIdentifier(true);
|
||||
|
||||
if (node.property.name !== propertyName) {
|
||||
this.raise(node.property.start, `The only valid meta property for new is ${meta.name}.${propertyName}`);
|
||||
this.raise(node.property.start, `The only valid meta property for ${meta.name} is ${meta.name}.${propertyName}`);
|
||||
}
|
||||
|
||||
return this.finishNode(node, "MetaProperty");
|
||||
}
|
||||
|
||||
parseImportMetaProperty(): N.MetaProperty {
|
||||
const node = this.startNode();
|
||||
const id = this.parseIdentifier(true);
|
||||
this.expect(tt.dot);
|
||||
if (!this.inModule) {
|
||||
this.raise(id.start, "import.meta may appear only with 'sourceType: module'");
|
||||
}
|
||||
return this.parseMetaProperty(node, id, "meta");
|
||||
}
|
||||
|
||||
parseLiteral<T : N.Literal>(value: any, type: /*T["kind"]*/string, startPos?: number, startLoc?: Position): T {
|
||||
startPos = startPos || this.state.start;
|
||||
startLoc = startLoc || this.state.startLoc;
|
||||
|
||||
@@ -106,7 +106,8 @@ export default class StatementParser extends ExpressionParser {
|
||||
case tt.semi: return this.parseEmptyStatement(node);
|
||||
case tt._export:
|
||||
case tt._import:
|
||||
if (this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL) break;
|
||||
if ((this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL) ||
|
||||
(this.hasPlugin("importMeta") && this.lookahead().type === tt.dot)) break;
|
||||
|
||||
if (!this.options.allowImportExportEverywhere) {
|
||||
if (!topLevel) {
|
||||
|
||||
@@ -17,18 +17,24 @@ import State from "./state";
|
||||
// The following character codes are forbidden from being
|
||||
// an immediate sibling of NumericLiteralSeparator _
|
||||
|
||||
const forbiddenNumericLiteralSeparatorSiblings = [
|
||||
46, // .
|
||||
66, // B
|
||||
69, // E
|
||||
79, // O
|
||||
88, // X
|
||||
95, // _ (multiple separators are not allowed)
|
||||
98, // b
|
||||
101, // e
|
||||
111, // o
|
||||
120, // x
|
||||
];
|
||||
const forbiddenNumericSeparatorSiblings = {
|
||||
decBinOct: [
|
||||
46, // .
|
||||
66, // B
|
||||
69, // E
|
||||
79, // O
|
||||
95, // _ (multiple separators are not allowed)
|
||||
98, // b
|
||||
101, // e
|
||||
111, // o
|
||||
],
|
||||
hex: [
|
||||
46, // .
|
||||
88, // X
|
||||
95, // _ (multiple separators are not allowed)
|
||||
120, // x
|
||||
],
|
||||
};
|
||||
|
||||
// Object type used to represent tokens. Note that normally, tokens
|
||||
// simply exist as properties on the parser object. This is only
|
||||
@@ -579,6 +585,9 @@ export default class Tokenizer extends LocationParser {
|
||||
|
||||
readInt(radix: number, len?: number): number | null {
|
||||
const start = this.state.pos;
|
||||
const forbiddenSiblings = radix === 16 ?
|
||||
forbiddenNumericSeparatorSiblings.hex :
|
||||
forbiddenNumericSeparatorSiblings.decBinOct;
|
||||
let total = 0;
|
||||
|
||||
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
||||
@@ -589,8 +598,8 @@ export default class Tokenizer extends LocationParser {
|
||||
const prev = this.input.charCodeAt(this.state.pos - 1);
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (code === 95) {
|
||||
if ((forbiddenNumericLiteralSeparatorSiblings.indexOf(prev) > -1) ||
|
||||
(forbiddenNumericLiteralSeparatorSiblings.indexOf(next) > -1) ||
|
||||
if ((forbiddenSiblings.indexOf(prev) > -1) ||
|
||||
(forbiddenSiblings.indexOf(next) > -1) ||
|
||||
Number.isNaN(next)) {
|
||||
this.raise(this.state.pos, "Invalid NumericLiteralSeparator");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user