Comparing version 3.29.0 to 3.30.0
@@ -34,3 +34,3 @@ import CJSImportProcessor from "./CJSImportProcessor"; | ||
/* istanbul ignore next */ | ||
return "3.29.0"; | ||
return "3.30.0"; | ||
} | ||
@@ -37,0 +37,0 @@ |
@@ -7,2 +7,3 @@ import {createCheckers} from "ts-interface-checker"; | ||
@@ -94,5 +95,4 @@ | ||
export function validateOptions(options) { | ||
OptionsChecker.strictCheck(options); | ||
} |
@@ -199,4 +199,6 @@ import { | ||
function tsParseTypeParameter() { | ||
eat(tt._const); | ||
const hadIn = eat(tt._in); | ||
const hadOut = eatContextual(ContextualKeyword._out); | ||
eat(tt._const); | ||
if ((hadIn || hadOut) && !match(tt.name)) { | ||
@@ -969,3 +971,3 @@ // The "in" or "out" keyword must have actually been the type parameter | ||
const oldIsType = pushTypeContext(1); | ||
parseVarStatement(state.type); | ||
parseVarStatement(state.type !== tt._var); | ||
popTypeContext(oldIsType); | ||
@@ -1143,5 +1145,3 @@ return true; | ||
* This hack is useful to handle situations like foo<<T>() => void>() where | ||
* there can legitimately be two open-angle-brackets in a row in TS. This | ||
* situation is very obscure and (as of this writing) is handled by Babel but | ||
* not TypeScript itself, so it may be fine in the future to remove this case. | ||
* there can legitimately be two open-angle-brackets in a row in TS. | ||
*/ | ||
@@ -1306,4 +1306,10 @@ function tsParseTypeArgumentsWithPossibleBitshift() { | ||
} else { | ||
if (isContextual(ContextualKeyword._type) && lookaheadType() === tt.braceL) { | ||
next(); | ||
if (isContextual(ContextualKeyword._type)) { | ||
const nextType = lookaheadType(); | ||
// export type {foo} from 'a'; | ||
// export type * from 'a';' | ||
// export type * as ns from 'a';' | ||
if (nextType === tt.braceL || nextType === tt.star) { | ||
next(); | ||
} | ||
} | ||
@@ -1310,0 +1316,0 @@ return false; |
@@ -515,7 +515,21 @@ /* eslint max-len: 0 */ | ||
} | ||
// This still might be two instances of <, e.g. the TS type argument | ||
// expression f<<T>() => void>() , but parse as left shift for now and we'll | ||
// retokenize if necessary. We can't use isType for this case because we | ||
// don't know yet if we're in a type. | ||
finishOp(tt.bitShiftL, 2); | ||
// We see <<, but need to be really careful about whether to treat it as a | ||
// true left-shift or as two < tokens. | ||
if (state.isType) { | ||
// Within a type, << might come up in a snippet like `Array<<T>() => void>`, | ||
// so treat it as two < tokens. Importantly, this should only override << | ||
// rather than other tokens like <= . If we treated <= as < in a type | ||
// context, then the snippet `a as T <= 1` would incorrectly start parsing | ||
// a type argument on T. We don't need to worry about `a as T << 1` | ||
// because TypeScript disallows that syntax. | ||
finishOp(tt.lessThan, 1); | ||
} else { | ||
// Outside a type, this might be a true left-shift operator, or it might | ||
// still be two open-type-arg tokens, such as in `f<<T>() => void>()`. We | ||
// look at the token while considering the `f`, so we don't yet know that | ||
// we're in a type context. In this case, we initially tokenize as a | ||
// left-shift and correct after-the-fact as necessary in | ||
// tsParseTypeArgumentsWithPossibleBitshift . | ||
finishOp(tt.bitShiftL, 2); | ||
} | ||
return; | ||
@@ -562,3 +576,10 @@ } | ||
* Called after `as` expressions in TS; we're switching from a type to a | ||
* non-type context, so a > token may actually be >= . | ||
* non-type context, so a > token may actually be >= . This is needed because >= | ||
* must be tokenized as a > in a type context because of code like | ||
* `const x: Array<T>=[];`, but `a as T >= 1` is a code example where it must be | ||
* treated as >=. | ||
* | ||
* Notably, this only applies to >, not <. In a code snippet like `a as T <= 1`, | ||
* we must NOT tokenize as <, or else the type parser will start parsing a type | ||
* argument and fail. | ||
*/ | ||
@@ -565,0 +586,0 @@ export function rescan_gt() { |
@@ -42,2 +42,3 @@ export var ContextualKeyword; (function (ContextualKeyword) { | ||
const _unique = _type + 1; ContextualKeyword[ContextualKeyword["_unique"] = _unique] = "_unique"; | ||
const _using = _unique + 1; ContextualKeyword[ContextualKeyword["_using"] = _using] = "_using"; | ||
})(ContextualKeyword || (ContextualKeyword = {})); |
@@ -8,3 +8,3 @@ // Generated file, do not edit! Run "yarn generate" to re-generate this file. | ||
// "" | ||
-1, 27, 783, 918, 1755, 2376, 2862, 3483, -1, 3699, -1, 4617, 4752, 4833, 5130, 5508, 5940, -1, 6480, 6939, 7749, 8181, 8343, 8505, -1, 8721, -1, | ||
-1, 27, 783, 918, 1755, 2376, 2862, 3483, -1, 3699, -1, 4617, 4752, 4833, 5130, 5508, 5940, -1, 6480, 6939, 7749, 8181, 8451, 8613, -1, 8829, -1, | ||
// "a" | ||
@@ -615,3 +615,3 @@ -1, -1, 54, 243, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 432, -1, -1, -1, 675, -1, -1, -1, | ||
// "u" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8208, -1, -1, -1, -1, 8343, -1, -1, -1, -1, -1, -1, -1, | ||
// "un" | ||
@@ -627,40 +627,48 @@ -1, -1, -1, -1, -1, -1, -1, -1, -1, 8235, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
ContextualKeyword._unique << 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "us" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8370, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "usi" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8397, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "usin" | ||
-1, -1, -1, -1, -1, -1, -1, 8424, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "using" | ||
ContextualKeyword._using << 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "v" | ||
-1, 8370, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8424, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, 8478, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8532, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "va" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8397, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8505, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "var" | ||
(tt._var << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "vo" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8451, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8559, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "voi" | ||
-1, -1, -1, -1, 8478, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, 8586, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "void" | ||
(tt._void << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "w" | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8532, 8640, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8640, 8748, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "wh" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8559, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8667, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "whi" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8586, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8694, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "whil" | ||
-1, -1, -1, -1, -1, 8613, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, 8721, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "while" | ||
(tt._while << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "wi" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8667, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8775, -1, -1, -1, -1, -1, -1, | ||
// "wit" | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8694, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8802, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "with" | ||
(tt._with << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "y" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8748, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8856, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yi" | ||
-1, -1, -1, -1, -1, 8775, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, 8883, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yie" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8802, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8910, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yiel" | ||
-1, -1, -1, -1, 8829, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, 8937, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yield" | ||
(tt._yield << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
]); |
@@ -82,5 +82,7 @@ /* eslint max-len: 0 */ | ||
expectContextual, | ||
hasFollowingLineBreak, | ||
hasPrecedingLineBreak, | ||
isContextual, | ||
isLineTerminator, | ||
isLookaheadContextual, | ||
semicolon, | ||
@@ -177,3 +179,3 @@ unexpected, | ||
case tt._var: | ||
parseVarStatement(starttype); | ||
parseVarStatement(starttype !== tt._var); | ||
return; | ||
@@ -217,2 +219,11 @@ | ||
} | ||
} else if ( | ||
state.contextualKeyword === ContextualKeyword._using && | ||
!hasFollowingLineBreak() && | ||
// Statements like `using[0]` and `using in foo` aren't actual using | ||
// declarations. | ||
lookaheadType() === tt.name | ||
) { | ||
parseVarStatement(true); | ||
return; | ||
} | ||
@@ -266,4 +277,4 @@ default: | ||
} | ||
parseMaybeDecoratorArguments(); | ||
} | ||
parseMaybeDecoratorArguments(); | ||
} | ||
@@ -315,2 +326,19 @@ | ||
/** | ||
* Determine if this token is a `using` declaration (explicit resource | ||
* management) as part of a loop. | ||
* https://github.com/tc39/proposal-explicit-resource-management | ||
*/ | ||
function isUsingInLoop() { | ||
if (!isContextual(ContextualKeyword._using)) { | ||
return false; | ||
} | ||
// This must be `for (using of`, where `using` is the name of the loop | ||
// variable. | ||
if (isLookaheadContextual(ContextualKeyword._of)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
// Disambiguating between a `for` and a `for`/`in` or `for`/`of` | ||
@@ -341,6 +369,5 @@ // loop is non-trivial. Basically, we have to parse the init `var` | ||
if (match(tt._var) || match(tt._let) || match(tt._const)) { | ||
const varKind = state.type; | ||
if (match(tt._var) || match(tt._let) || match(tt._const) || isUsingInLoop()) { | ||
next(); | ||
parseVar(true, varKind); | ||
parseVar(true, state.type !== tt._var); | ||
if (match(tt._in) || isContextual(ContextualKeyword._of)) { | ||
@@ -462,5 +489,5 @@ parseForIn(forAwait); | ||
export function parseVarStatement(kind) { | ||
export function parseVarStatement(isBlockScope) { | ||
next(); | ||
parseVar(false, kind); | ||
parseVar(false, isBlockScope); | ||
semicolon(); | ||
@@ -553,5 +580,4 @@ } | ||
function parseVar(isFor, kind) { | ||
function parseVar(isFor, isBlockScope) { | ||
while (true) { | ||
const isBlockScope = kind === tt._const || kind === tt._let; | ||
parseVarHead(isBlockScope); | ||
@@ -1094,2 +1120,46 @@ if (eat(tt.eq)) { | ||
/** | ||
* Starting at the `module` token in an import, determine if it was truly an | ||
* import reflection token or just looks like one. | ||
* | ||
* Returns true for: | ||
* import module foo from "foo"; | ||
* import module from from "foo"; | ||
* | ||
* Returns false for: | ||
* import module from "foo"; | ||
* import module, {bar} from "foo"; | ||
*/ | ||
function isImportReflection() { | ||
const snapshot = state.snapshot(); | ||
expectContextual(ContextualKeyword._module); | ||
if (eatContextual(ContextualKeyword._from)) { | ||
if (isContextual(ContextualKeyword._from)) { | ||
state.restoreFromSnapshot(snapshot); | ||
return true; | ||
} else { | ||
state.restoreFromSnapshot(snapshot); | ||
return false; | ||
} | ||
} else if (match(tt.comma)) { | ||
state.restoreFromSnapshot(snapshot); | ||
return false; | ||
} else { | ||
state.restoreFromSnapshot(snapshot); | ||
return true; | ||
} | ||
} | ||
/** | ||
* Eat the "module" token from the import reflection proposal. | ||
* https://github.com/tc39/proposal-import-reflection | ||
*/ | ||
function parseMaybeImportReflection() { | ||
// isImportReflection does snapshot/restore, so only run it if we see the word | ||
// "module". | ||
if (isContextual(ContextualKeyword._module) && isImportReflection()) { | ||
next(); | ||
} | ||
} | ||
// Parses import declaration. | ||
@@ -1129,2 +1199,3 @@ | ||
} else { | ||
parseMaybeImportReflection(); | ||
parseImportSpecifiers(); | ||
@@ -1131,0 +1202,0 @@ expectContextual(ContextualKeyword._from); |
@@ -307,3 +307,4 @@ | ||
this.tokens.matches2(tt._export, tt._class) || | ||
this.tokens.matches3(tt._export, tt._abstract, tt._class) | ||
this.tokens.matches3(tt._export, tt._abstract, tt._class) || | ||
this.tokens.matches2(tt._export, tt.at) | ||
) { | ||
@@ -319,12 +320,27 @@ this.processExportClass(); | ||
} else if ( | ||
this.tokens.matches3(tt._export, tt.name, tt.braceL) && | ||
this.tokens.matches2(tt._export, tt.name) && | ||
this.tokens.matchesContextualAtIndex(this.tokens.currentIndex() + 1, ContextualKeyword._type) | ||
) { | ||
// TS `export type {` case: just remove the export entirely. | ||
// export type {a}; | ||
// export type {a as b}; | ||
// export type {a} from './b'; | ||
// export type * from './b'; | ||
// export type * as ns from './b'; | ||
this.tokens.removeInitialToken(); | ||
while (!this.tokens.matches1(tt.braceR)) { | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt.braceL)) { | ||
while (!this.tokens.matches1(tt.braceR)) { | ||
this.tokens.removeToken(); | ||
} | ||
this.tokens.removeToken(); | ||
} else { | ||
// * | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt._as)) { | ||
// as | ||
this.tokens.removeToken(); | ||
// ns | ||
this.tokens.removeToken(); | ||
} | ||
} | ||
this.tokens.removeToken(); | ||
// Remove type re-export `... } from './T'` | ||
@@ -488,6 +504,8 @@ if ( | ||
this.tokens.matches4(tt._export, tt._default, tt._class, tt.name) || | ||
this.tokens.matches5(tt._export, tt._default, tt._abstract, tt._class, tt.name) | ||
this.tokens.matches5(tt._export, tt._default, tt._abstract, tt._class, tt.name) || | ||
this.tokens.matches3(tt._export, tt._default, tt.at) | ||
) { | ||
this.tokens.removeInitialToken(); | ||
this.tokens.removeToken(); | ||
this.copyDecorators(); | ||
if (this.tokens.matches1(tt._abstract)) { | ||
@@ -498,4 +516,2 @@ this.tokens.removeToken(); | ||
this.tokens.appendCode(` exports.default = ${name};`); | ||
} else if (this.tokens.matches3(tt._export, tt._default, tt.at)) { | ||
throw new Error("Export default statements with decorators are not yet supported."); | ||
// After this point, this is a plain "export default E" statement. | ||
@@ -527,2 +543,24 @@ } else if ( | ||
copyDecorators() { | ||
while (this.tokens.matches1(tt.at)) { | ||
this.tokens.copyToken(); | ||
if (this.tokens.matches1(tt.parenL)) { | ||
this.tokens.copyExpectedToken(tt.parenL); | ||
this.rootTransformer.processBalancedCode(); | ||
this.tokens.copyExpectedToken(tt.parenR); | ||
} else { | ||
this.tokens.copyExpectedToken(tt.name); | ||
while (this.tokens.matches1(tt.dot)) { | ||
this.tokens.copyExpectedToken(tt.dot); | ||
this.tokens.copyExpectedToken(tt.name); | ||
} | ||
if (this.tokens.matches1(tt.parenL)) { | ||
this.tokens.copyExpectedToken(tt.parenL); | ||
this.rootTransformer.processBalancedCode(); | ||
this.tokens.copyExpectedToken(tt.parenR); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
@@ -727,2 +765,3 @@ * Transform a declaration like `export var`, `export let`, or `export const`. | ||
this.tokens.removeInitialToken(); | ||
this.copyDecorators(); | ||
if (this.tokens.matches1(tt._abstract)) { | ||
@@ -729,0 +768,0 @@ this.tokens.removeToken(); |
@@ -89,12 +89,27 @@ | ||
if ( | ||
this.tokens.matches3(tt._export, tt.name, tt.braceL) && | ||
this.tokens.matches2(tt._export, tt.name) && | ||
this.tokens.matchesContextualAtIndex(this.tokens.currentIndex() + 1, ContextualKeyword._type) | ||
) { | ||
// TS `export type {` case: just remove the export entirely. | ||
// export type {a}; | ||
// export type {a as b}; | ||
// export type {a} from './b'; | ||
// export type * from './b'; | ||
// export type * as ns from './b'; | ||
this.tokens.removeInitialToken(); | ||
while (!this.tokens.matches1(tt.braceR)) { | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt.braceL)) { | ||
while (!this.tokens.matches1(tt.braceR)) { | ||
this.tokens.removeToken(); | ||
} | ||
this.tokens.removeToken(); | ||
} else { | ||
// * | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt._as)) { | ||
// as | ||
this.tokens.removeToken(); | ||
// ns | ||
this.tokens.removeToken(); | ||
} | ||
} | ||
this.tokens.removeToken(); | ||
// Remove type re-export `... } from './T'` | ||
@@ -182,2 +197,10 @@ if ( | ||
// Skip the "module" token in import reflection. | ||
if ( | ||
this.tokens.matchesContextual(ContextualKeyword._module) && | ||
this.tokens.matchesContextualAtIndex(this.tokens.currentIndex() + 2, ContextualKeyword._from) | ||
) { | ||
this.tokens.copyToken(); | ||
} | ||
let foundNonTypeImport = false; | ||
@@ -184,0 +207,0 @@ let needsComma = false; |
import {TokenType as tt} from "../parser/tokenizer/types"; | ||
@@ -17,3 +18,2 @@ | ||
/** | ||
@@ -20,0 +20,0 @@ * Determine information about this named import or named export specifier. |
@@ -34,3 +34,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _CJSImportProcessor = require('./CJSImportProcessor'); var _CJSImportProcessor2 = _interopRequireDefault(_CJSImportProcessor); | ||
/* istanbul ignore next */ | ||
return "3.29.0"; | ||
return "3.30.0"; | ||
} exports.getVersion = getVersion; | ||
@@ -37,0 +37,0 @@ |
@@ -199,4 +199,6 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
function tsParseTypeParameter() { | ||
_index.eat.call(void 0, _types.TokenType._const); | ||
const hadIn = _index.eat.call(void 0, _types.TokenType._in); | ||
const hadOut = _util.eatContextual.call(void 0, _keywords.ContextualKeyword._out); | ||
_index.eat.call(void 0, _types.TokenType._const); | ||
if ((hadIn || hadOut) && !_index.match.call(void 0, _types.TokenType.name)) { | ||
@@ -969,3 +971,3 @@ // The "in" or "out" keyword must have actually been the type parameter | ||
const oldIsType = _index.pushTypeContext.call(void 0, 1); | ||
_statement.parseVarStatement.call(void 0, _base.state.type); | ||
_statement.parseVarStatement.call(void 0, _base.state.type !== _types.TokenType._var); | ||
_index.popTypeContext.call(void 0, oldIsType); | ||
@@ -1143,5 +1145,3 @@ return true; | ||
* This hack is useful to handle situations like foo<<T>() => void>() where | ||
* there can legitimately be two open-angle-brackets in a row in TS. This | ||
* situation is very obscure and (as of this writing) is handled by Babel but | ||
* not TypeScript itself, so it may be fine in the future to remove this case. | ||
* there can legitimately be two open-angle-brackets in a row in TS. | ||
*/ | ||
@@ -1306,4 +1306,10 @@ function tsParseTypeArgumentsWithPossibleBitshift() { | ||
} else { | ||
if (_util.isContextual.call(void 0, _keywords.ContextualKeyword._type) && _index.lookaheadType.call(void 0, ) === _types.TokenType.braceL) { | ||
_index.next.call(void 0, ); | ||
if (_util.isContextual.call(void 0, _keywords.ContextualKeyword._type)) { | ||
const nextType = _index.lookaheadType.call(void 0, ); | ||
// export type {foo} from 'a'; | ||
// export type * from 'a';' | ||
// export type * as ns from 'a';' | ||
if (nextType === _types.TokenType.braceL || nextType === _types.TokenType.star) { | ||
_index.next.call(void 0, ); | ||
} | ||
} | ||
@@ -1310,0 +1316,0 @@ return false; |
@@ -515,7 +515,21 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }/* eslint max-len: 0 */ | ||
} | ||
// This still might be two instances of <, e.g. the TS type argument | ||
// expression f<<T>() => void>() , but parse as left shift for now and we'll | ||
// retokenize if necessary. We can't use isType for this case because we | ||
// don't know yet if we're in a type. | ||
finishOp(_types.TokenType.bitShiftL, 2); | ||
// We see <<, but need to be really careful about whether to treat it as a | ||
// true left-shift or as two < tokens. | ||
if (_base.state.isType) { | ||
// Within a type, << might come up in a snippet like `Array<<T>() => void>`, | ||
// so treat it as two < tokens. Importantly, this should only override << | ||
// rather than other tokens like <= . If we treated <= as < in a type | ||
// context, then the snippet `a as T <= 1` would incorrectly start parsing | ||
// a type argument on T. We don't need to worry about `a as T << 1` | ||
// because TypeScript disallows that syntax. | ||
finishOp(_types.TokenType.lessThan, 1); | ||
} else { | ||
// Outside a type, this might be a true left-shift operator, or it might | ||
// still be two open-type-arg tokens, such as in `f<<T>() => void>()`. We | ||
// look at the token while considering the `f`, so we don't yet know that | ||
// we're in a type context. In this case, we initially tokenize as a | ||
// left-shift and correct after-the-fact as necessary in | ||
// tsParseTypeArgumentsWithPossibleBitshift . | ||
finishOp(_types.TokenType.bitShiftL, 2); | ||
} | ||
return; | ||
@@ -562,3 +576,10 @@ } | ||
* Called after `as` expressions in TS; we're switching from a type to a | ||
* non-type context, so a > token may actually be >= . | ||
* non-type context, so a > token may actually be >= . This is needed because >= | ||
* must be tokenized as a > in a type context because of code like | ||
* `const x: Array<T>=[];`, but `a as T >= 1` is a code example where it must be | ||
* treated as >=. | ||
* | ||
* Notably, this only applies to >, not <. In a code snippet like `a as T <= 1`, | ||
* we must NOT tokenize as <, or else the type parser will start parsing a type | ||
* argument and fail. | ||
*/ | ||
@@ -565,0 +586,0 @@ function rescan_gt() { |
@@ -42,2 +42,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var ContextualKeyword; (function (ContextualKeyword) { | ||
const _unique = _type + 1; ContextualKeyword[ContextualKeyword["_unique"] = _unique] = "_unique"; | ||
const _using = _unique + 1; ContextualKeyword[ContextualKeyword["_using"] = _using] = "_using"; | ||
})(ContextualKeyword || (exports.ContextualKeyword = ContextualKeyword = {})); |
@@ -8,3 +8,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// Generated file, do not edit! Run "yarn generate" to re-generate this file. | ||
// "" | ||
-1, 27, 783, 918, 1755, 2376, 2862, 3483, -1, 3699, -1, 4617, 4752, 4833, 5130, 5508, 5940, -1, 6480, 6939, 7749, 8181, 8343, 8505, -1, 8721, -1, | ||
-1, 27, 783, 918, 1755, 2376, 2862, 3483, -1, 3699, -1, 4617, 4752, 4833, 5130, 5508, 5940, -1, 6480, 6939, 7749, 8181, 8451, 8613, -1, 8829, -1, | ||
// "a" | ||
@@ -615,3 +615,3 @@ -1, -1, 54, 243, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 432, -1, -1, -1, 675, -1, -1, -1, | ||
// "u" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8208, -1, -1, -1, -1, 8343, -1, -1, -1, -1, -1, -1, -1, | ||
// "un" | ||
@@ -627,40 +627,48 @@ -1, -1, -1, -1, -1, -1, -1, -1, -1, 8235, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
_keywords.ContextualKeyword._unique << 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "us" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8370, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "usi" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8397, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "usin" | ||
-1, -1, -1, -1, -1, -1, -1, 8424, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "using" | ||
_keywords.ContextualKeyword._using << 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "v" | ||
-1, 8370, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8424, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, 8478, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8532, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "va" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8397, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8505, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "var" | ||
(_types.TokenType._var << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "vo" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8451, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8559, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "voi" | ||
-1, -1, -1, -1, 8478, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, 8586, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "void" | ||
(_types.TokenType._void << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "w" | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8532, 8640, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8640, 8748, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "wh" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8559, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8667, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "whi" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8586, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8694, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "whil" | ||
-1, -1, -1, -1, -1, 8613, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, 8721, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "while" | ||
(_types.TokenType._while << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "wi" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8667, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8775, -1, -1, -1, -1, -1, -1, | ||
// "wit" | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8694, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, 8802, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "with" | ||
(_types.TokenType._with << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "y" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8748, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 8856, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yi" | ||
-1, -1, -1, -1, -1, 8775, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, 8883, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yie" | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8802, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8910, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yiel" | ||
-1, -1, -1, -1, 8829, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
-1, -1, -1, -1, 8937, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
// "yield" | ||
(_types.TokenType._yield << 1) + 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
]); exports.READ_WORD_TREE = READ_WORD_TREE; |
@@ -87,2 +87,4 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});/* eslint max-len: 0 */ | ||
var _util = require('./util'); | ||
@@ -177,3 +179,3 @@ | ||
case _types.TokenType._var: | ||
parseVarStatement(starttype); | ||
parseVarStatement(starttype !== _types.TokenType._var); | ||
return; | ||
@@ -217,2 +219,11 @@ | ||
} | ||
} else if ( | ||
_base.state.contextualKeyword === _keywords.ContextualKeyword._using && | ||
!_util.hasFollowingLineBreak.call(void 0, ) && | ||
// Statements like `using[0]` and `using in foo` aren't actual using | ||
// declarations. | ||
_tokenizer.lookaheadType.call(void 0, ) === _types.TokenType.name | ||
) { | ||
parseVarStatement(true); | ||
return; | ||
} | ||
@@ -266,4 +277,4 @@ default: | ||
} | ||
parseMaybeDecoratorArguments(); | ||
} | ||
parseMaybeDecoratorArguments(); | ||
} | ||
@@ -315,2 +326,19 @@ | ||
/** | ||
* Determine if this token is a `using` declaration (explicit resource | ||
* management) as part of a loop. | ||
* https://github.com/tc39/proposal-explicit-resource-management | ||
*/ | ||
function isUsingInLoop() { | ||
if (!_util.isContextual.call(void 0, _keywords.ContextualKeyword._using)) { | ||
return false; | ||
} | ||
// This must be `for (using of`, where `using` is the name of the loop | ||
// variable. | ||
if (_util.isLookaheadContextual.call(void 0, _keywords.ContextualKeyword._of)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
// Disambiguating between a `for` and a `for`/`in` or `for`/`of` | ||
@@ -341,6 +369,5 @@ // loop is non-trivial. Basically, we have to parse the init `var` | ||
if (_tokenizer.match.call(void 0, _types.TokenType._var) || _tokenizer.match.call(void 0, _types.TokenType._let) || _tokenizer.match.call(void 0, _types.TokenType._const)) { | ||
const varKind = _base.state.type; | ||
if (_tokenizer.match.call(void 0, _types.TokenType._var) || _tokenizer.match.call(void 0, _types.TokenType._let) || _tokenizer.match.call(void 0, _types.TokenType._const) || isUsingInLoop()) { | ||
_tokenizer.next.call(void 0, ); | ||
parseVar(true, varKind); | ||
parseVar(true, _base.state.type !== _types.TokenType._var); | ||
if (_tokenizer.match.call(void 0, _types.TokenType._in) || _util.isContextual.call(void 0, _keywords.ContextualKeyword._of)) { | ||
@@ -462,5 +489,5 @@ parseForIn(forAwait); | ||
function parseVarStatement(kind) { | ||
function parseVarStatement(isBlockScope) { | ||
_tokenizer.next.call(void 0, ); | ||
parseVar(false, kind); | ||
parseVar(false, isBlockScope); | ||
_util.semicolon.call(void 0, ); | ||
@@ -553,5 +580,4 @@ } exports.parseVarStatement = parseVarStatement; | ||
function parseVar(isFor, kind) { | ||
function parseVar(isFor, isBlockScope) { | ||
while (true) { | ||
const isBlockScope = kind === _types.TokenType._const || kind === _types.TokenType._let; | ||
parseVarHead(isBlockScope); | ||
@@ -1094,2 +1120,46 @@ if (_tokenizer.eat.call(void 0, _types.TokenType.eq)) { | ||
/** | ||
* Starting at the `module` token in an import, determine if it was truly an | ||
* import reflection token or just looks like one. | ||
* | ||
* Returns true for: | ||
* import module foo from "foo"; | ||
* import module from from "foo"; | ||
* | ||
* Returns false for: | ||
* import module from "foo"; | ||
* import module, {bar} from "foo"; | ||
*/ | ||
function isImportReflection() { | ||
const snapshot = _base.state.snapshot(); | ||
_util.expectContextual.call(void 0, _keywords.ContextualKeyword._module); | ||
if (_util.eatContextual.call(void 0, _keywords.ContextualKeyword._from)) { | ||
if (_util.isContextual.call(void 0, _keywords.ContextualKeyword._from)) { | ||
_base.state.restoreFromSnapshot(snapshot); | ||
return true; | ||
} else { | ||
_base.state.restoreFromSnapshot(snapshot); | ||
return false; | ||
} | ||
} else if (_tokenizer.match.call(void 0, _types.TokenType.comma)) { | ||
_base.state.restoreFromSnapshot(snapshot); | ||
return false; | ||
} else { | ||
_base.state.restoreFromSnapshot(snapshot); | ||
return true; | ||
} | ||
} | ||
/** | ||
* Eat the "module" token from the import reflection proposal. | ||
* https://github.com/tc39/proposal-import-reflection | ||
*/ | ||
function parseMaybeImportReflection() { | ||
// isImportReflection does snapshot/restore, so only run it if we see the word | ||
// "module". | ||
if (_util.isContextual.call(void 0, _keywords.ContextualKeyword._module) && isImportReflection()) { | ||
_tokenizer.next.call(void 0, ); | ||
} | ||
} | ||
// Parses import declaration. | ||
@@ -1129,2 +1199,3 @@ | ||
} else { | ||
parseMaybeImportReflection(); | ||
parseImportSpecifiers(); | ||
@@ -1131,0 +1202,0 @@ _util.expectContextual.call(void 0, _keywords.ContextualKeyword._from); |
@@ -307,3 +307,4 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
this.tokens.matches2(_types.TokenType._export, _types.TokenType._class) || | ||
this.tokens.matches3(_types.TokenType._export, _types.TokenType._abstract, _types.TokenType._class) | ||
this.tokens.matches3(_types.TokenType._export, _types.TokenType._abstract, _types.TokenType._class) || | ||
this.tokens.matches2(_types.TokenType._export, _types.TokenType.at) | ||
) { | ||
@@ -319,12 +320,27 @@ this.processExportClass(); | ||
} else if ( | ||
this.tokens.matches3(_types.TokenType._export, _types.TokenType.name, _types.TokenType.braceL) && | ||
this.tokens.matches2(_types.TokenType._export, _types.TokenType.name) && | ||
this.tokens.matchesContextualAtIndex(this.tokens.currentIndex() + 1, _keywords.ContextualKeyword._type) | ||
) { | ||
// TS `export type {` case: just remove the export entirely. | ||
// export type {a}; | ||
// export type {a as b}; | ||
// export type {a} from './b'; | ||
// export type * from './b'; | ||
// export type * as ns from './b'; | ||
this.tokens.removeInitialToken(); | ||
while (!this.tokens.matches1(_types.TokenType.braceR)) { | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType.braceL)) { | ||
while (!this.tokens.matches1(_types.TokenType.braceR)) { | ||
this.tokens.removeToken(); | ||
} | ||
this.tokens.removeToken(); | ||
} else { | ||
// * | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType._as)) { | ||
// as | ||
this.tokens.removeToken(); | ||
// ns | ||
this.tokens.removeToken(); | ||
} | ||
} | ||
this.tokens.removeToken(); | ||
// Remove type re-export `... } from './T'` | ||
@@ -488,6 +504,8 @@ if ( | ||
this.tokens.matches4(_types.TokenType._export, _types.TokenType._default, _types.TokenType._class, _types.TokenType.name) || | ||
this.tokens.matches5(_types.TokenType._export, _types.TokenType._default, _types.TokenType._abstract, _types.TokenType._class, _types.TokenType.name) | ||
this.tokens.matches5(_types.TokenType._export, _types.TokenType._default, _types.TokenType._abstract, _types.TokenType._class, _types.TokenType.name) || | ||
this.tokens.matches3(_types.TokenType._export, _types.TokenType._default, _types.TokenType.at) | ||
) { | ||
this.tokens.removeInitialToken(); | ||
this.tokens.removeToken(); | ||
this.copyDecorators(); | ||
if (this.tokens.matches1(_types.TokenType._abstract)) { | ||
@@ -498,4 +516,2 @@ this.tokens.removeToken(); | ||
this.tokens.appendCode(` exports.default = ${name};`); | ||
} else if (this.tokens.matches3(_types.TokenType._export, _types.TokenType._default, _types.TokenType.at)) { | ||
throw new Error("Export default statements with decorators are not yet supported."); | ||
// After this point, this is a plain "export default E" statement. | ||
@@ -527,2 +543,24 @@ } else if ( | ||
copyDecorators() { | ||
while (this.tokens.matches1(_types.TokenType.at)) { | ||
this.tokens.copyToken(); | ||
if (this.tokens.matches1(_types.TokenType.parenL)) { | ||
this.tokens.copyExpectedToken(_types.TokenType.parenL); | ||
this.rootTransformer.processBalancedCode(); | ||
this.tokens.copyExpectedToken(_types.TokenType.parenR); | ||
} else { | ||
this.tokens.copyExpectedToken(_types.TokenType.name); | ||
while (this.tokens.matches1(_types.TokenType.dot)) { | ||
this.tokens.copyExpectedToken(_types.TokenType.dot); | ||
this.tokens.copyExpectedToken(_types.TokenType.name); | ||
} | ||
if (this.tokens.matches1(_types.TokenType.parenL)) { | ||
this.tokens.copyExpectedToken(_types.TokenType.parenL); | ||
this.rootTransformer.processBalancedCode(); | ||
this.tokens.copyExpectedToken(_types.TokenType.parenR); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
@@ -727,2 +765,3 @@ * Transform a declaration like `export var`, `export let`, or `export const`. | ||
this.tokens.removeInitialToken(); | ||
this.copyDecorators(); | ||
if (this.tokens.matches1(_types.TokenType._abstract)) { | ||
@@ -729,0 +768,0 @@ this.tokens.removeToken(); |
@@ -89,12 +89,27 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if ( | ||
this.tokens.matches3(_types.TokenType._export, _types.TokenType.name, _types.TokenType.braceL) && | ||
this.tokens.matches2(_types.TokenType._export, _types.TokenType.name) && | ||
this.tokens.matchesContextualAtIndex(this.tokens.currentIndex() + 1, _keywords.ContextualKeyword._type) | ||
) { | ||
// TS `export type {` case: just remove the export entirely. | ||
// export type {a}; | ||
// export type {a as b}; | ||
// export type {a} from './b'; | ||
// export type * from './b'; | ||
// export type * as ns from './b'; | ||
this.tokens.removeInitialToken(); | ||
while (!this.tokens.matches1(_types.TokenType.braceR)) { | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType.braceL)) { | ||
while (!this.tokens.matches1(_types.TokenType.braceR)) { | ||
this.tokens.removeToken(); | ||
} | ||
this.tokens.removeToken(); | ||
} else { | ||
// * | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType._as)) { | ||
// as | ||
this.tokens.removeToken(); | ||
// ns | ||
this.tokens.removeToken(); | ||
} | ||
} | ||
this.tokens.removeToken(); | ||
// Remove type re-export `... } from './T'` | ||
@@ -182,2 +197,10 @@ if ( | ||
// Skip the "module" token in import reflection. | ||
if ( | ||
this.tokens.matchesContextual(_keywords.ContextualKeyword._module) && | ||
this.tokens.matchesContextualAtIndex(this.tokens.currentIndex() + 2, _keywords.ContextualKeyword._from) | ||
) { | ||
this.tokens.copyToken(); | ||
} | ||
let foundNonTypeImport = false; | ||
@@ -184,0 +207,0 @@ let needsComma = false; |
@@ -79,3 +79,10 @@ import { ContextualKeyword } from "./keywords"; | ||
* Called after `as` expressions in TS; we're switching from a type to a | ||
* non-type context, so a > token may actually be >= . | ||
* non-type context, so a > token may actually be >= . This is needed because >= | ||
* must be tokenized as a > in a type context because of code like | ||
* `const x: Array<T>=[];`, but `a as T >= 1` is a code example where it must be | ||
* treated as >=. | ||
* | ||
* Notably, this only applies to >, not <. In a code snippet like `a as T <= 1`, | ||
* we must NOT tokenize as <, or else the type parser will start parsing a type | ||
* argument and fail. | ||
*/ | ||
@@ -82,0 +89,0 @@ export declare function rescan_gt(): void; |
@@ -41,3 +41,4 @@ export declare enum ContextualKeyword { | ||
_type = 38, | ||
_unique = 39 | ||
_unique = 39, | ||
_using = 40 | ||
} |
@@ -7,3 +7,3 @@ import { File } from "../index"; | ||
export declare function baseParseMaybeDecoratorArguments(): void; | ||
export declare function parseVarStatement(kind: TokenType): void; | ||
export declare function parseVarStatement(isBlockScope: boolean): void; | ||
export declare function parseBlock(isFunctionScope?: boolean, contextId?: number): void; | ||
@@ -10,0 +10,0 @@ export declare function parseBlockBody(end: TokenType): void; |
@@ -64,2 +64,3 @@ import type CJSImportProcessor from "../CJSImportProcessor"; | ||
private processExportDefault; | ||
private copyDecorators; | ||
/** | ||
@@ -66,0 +67,0 @@ * Transform a declaration like `export var`, `export let`, or `export const`. |
{ | ||
"name": "sucrase", | ||
"version": "3.29.0", | ||
"version": "3.30.0", | ||
"description": "Super-fast alternative to Babel for when you can target modern JS runtimes", | ||
@@ -62,3 +62,3 @@ "author": "Alan Pierce <alangpierce@gmail.com>", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-import": "~2.26", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
@@ -68,6 +68,6 @@ "mocha": "^10.0.0", | ||
"prettier": "^2.6.2", | ||
"sucrase": "^3.28.0", | ||
"sucrase": "^3.29.0", | ||
"test262-harness": "^10.0.0", | ||
"ts-interface-builder": "^0.3.3", | ||
"typescript": "^4.7.3" | ||
"typescript": "~4.7" | ||
}, | ||
@@ -74,0 +74,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1105581
27882