Comparing version 3.22.0 to 3.23.0
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -8,2 +8,3 @@ | ||
var _getImportExportSpecifierInfo = require('./util/getImportExportSpecifierInfo'); var _getImportExportSpecifierInfo2 = _interopRequireDefault(_getImportExportSpecifierInfo); | ||
var _getNonTypeIdentifiers = require('./util/getNonTypeIdentifiers'); | ||
@@ -363,27 +364,11 @@ | ||
// Flow type imports should just be ignored. | ||
let isTypeImport = false; | ||
if ( | ||
(this.tokens.matchesContextualAtIndex(index, _keywords.ContextualKeyword._type) || | ||
this.tokens.matches1AtIndex(index, _types.TokenType._typeof)) && | ||
this.tokens.matches1AtIndex(index + 1, _types.TokenType.name) && | ||
!this.tokens.matchesContextualAtIndex(index + 1, _keywords.ContextualKeyword._as) | ||
) { | ||
isTypeImport = true; | ||
index++; | ||
const specifierInfo = _getImportExportSpecifierInfo2.default.call(void 0, this.tokens, index); | ||
index = specifierInfo.endIndex; | ||
if (!specifierInfo.isType) { | ||
namedImports.push({ | ||
importedName: specifierInfo.leftName, | ||
localName: specifierInfo.rightName, | ||
}); | ||
} | ||
const importedName = this.tokens.identifierNameAtIndex(index); | ||
let localName; | ||
index++; | ||
if (this.tokens.matchesContextualAtIndex(index, _keywords.ContextualKeyword._as)) { | ||
index++; | ||
localName = this.tokens.identifierNameAtIndex(index); | ||
index++; | ||
} else { | ||
localName = importedName; | ||
} | ||
if (!isTypeImport) { | ||
namedImports.push({importedName, localName}); | ||
} | ||
if (this.tokens.matches2AtIndex(index, _types.TokenType.comma, _types.TokenType.braceR)) { | ||
@@ -390,0 +375,0 @@ index += 2; |
@@ -8,2 +8,3 @@ | ||
import getImportExportSpecifierInfo from "./util/getImportExportSpecifierInfo"; | ||
import {getNonTypeIdentifiers} from "./util/getNonTypeIdentifiers"; | ||
@@ -363,27 +364,11 @@ | ||
// Flow type imports should just be ignored. | ||
let isTypeImport = false; | ||
if ( | ||
(this.tokens.matchesContextualAtIndex(index, ContextualKeyword._type) || | ||
this.tokens.matches1AtIndex(index, tt._typeof)) && | ||
this.tokens.matches1AtIndex(index + 1, tt.name) && | ||
!this.tokens.matchesContextualAtIndex(index + 1, ContextualKeyword._as) | ||
) { | ||
isTypeImport = true; | ||
index++; | ||
const specifierInfo = getImportExportSpecifierInfo(this.tokens, index); | ||
index = specifierInfo.endIndex; | ||
if (!specifierInfo.isType) { | ||
namedImports.push({ | ||
importedName: specifierInfo.leftName, | ||
localName: specifierInfo.rightName, | ||
}); | ||
} | ||
const importedName = this.tokens.identifierNameAtIndex(index); | ||
let localName; | ||
index++; | ||
if (this.tokens.matchesContextualAtIndex(index, ContextualKeyword._as)) { | ||
index++; | ||
localName = this.tokens.identifierNameAtIndex(index); | ||
index++; | ||
} else { | ||
localName = importedName; | ||
} | ||
if (!isTypeImport) { | ||
namedImports.push({importedName, localName}); | ||
} | ||
if (this.tokens.matches2AtIndex(index, tt.comma, tt.braceR)) { | ||
@@ -390,0 +375,0 @@ index += 2; |
@@ -33,3 +33,3 @@ import CJSImportProcessor from "./CJSImportProcessor"; | ||
export function getVersion() { | ||
return "3.22.0"; | ||
return "3.23.0"; | ||
} | ||
@@ -36,0 +36,0 @@ |
import { | ||
eat, | ||
IdentifierRole, | ||
lookaheadType, | ||
@@ -1259,2 +1260,78 @@ lookaheadTypeAndKeyword, | ||
/** | ||
* Parse a TS import specifier, which may be prefixed with "type" and may be of | ||
* the form `foo as bar`. | ||
* | ||
* The number of identifier-like tokens we see happens to be enough to uniquely | ||
* identify the form, so simply count the number of identifiers rather than | ||
* matching the words `type` or `as`. This is particularly important because | ||
* `type` and `as` could each actually be plain identifiers rather than | ||
* keywords. | ||
*/ | ||
export function tsParseImportSpecifier() { | ||
parseIdentifier(); | ||
if (match(tt.comma) || match(tt.braceR)) { | ||
// import {foo} | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ImportDeclaration; | ||
return; | ||
} | ||
parseIdentifier(); | ||
if (match(tt.comma) || match(tt.braceR)) { | ||
// import {type foo} | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ImportDeclaration; | ||
state.tokens[state.tokens.length - 2].isType = true; | ||
state.tokens[state.tokens.length - 1].isType = true; | ||
return; | ||
} | ||
parseIdentifier(); | ||
if (match(tt.comma) || match(tt.braceR)) { | ||
// import {foo as bar} | ||
state.tokens[state.tokens.length - 3].identifierRole = IdentifierRole.ImportAccess; | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ImportDeclaration; | ||
return; | ||
} | ||
parseIdentifier(); | ||
// import {type foo as bar} | ||
state.tokens[state.tokens.length - 3].identifierRole = IdentifierRole.ImportAccess; | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ImportDeclaration; | ||
state.tokens[state.tokens.length - 4].isType = true; | ||
state.tokens[state.tokens.length - 3].isType = true; | ||
state.tokens[state.tokens.length - 2].isType = true; | ||
state.tokens[state.tokens.length - 1].isType = true; | ||
} | ||
/** | ||
* Just like named import specifiers, export specifiers can have from 1 to 4 | ||
* tokens, inclusive, and the number of tokens determines the role of each token. | ||
*/ | ||
export function tsParseExportSpecifier() { | ||
parseIdentifier(); | ||
if (match(tt.comma) || match(tt.braceR)) { | ||
// export {foo} | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ExportAccess; | ||
return; | ||
} | ||
parseIdentifier(); | ||
if (match(tt.comma) || match(tt.braceR)) { | ||
// export {type foo} | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ExportAccess; | ||
state.tokens[state.tokens.length - 2].isType = true; | ||
state.tokens[state.tokens.length - 1].isType = true; | ||
return; | ||
} | ||
parseIdentifier(); | ||
if (match(tt.comma) || match(tt.braceR)) { | ||
// export {foo as bar} | ||
state.tokens[state.tokens.length - 3].identifierRole = IdentifierRole.ExportAccess; | ||
return; | ||
} | ||
parseIdentifier(); | ||
// export {type foo as bar} | ||
state.tokens[state.tokens.length - 3].identifierRole = IdentifierRole.ExportAccess; | ||
state.tokens[state.tokens.length - 4].isType = true; | ||
state.tokens[state.tokens.length - 3].isType = true; | ||
state.tokens[state.tokens.length - 2].isType = true; | ||
state.tokens[state.tokens.length - 1].isType = true; | ||
} | ||
export function tsTryParseExportDefaultExpression() { | ||
@@ -1261,0 +1338,0 @@ if (isContextual(ContextualKeyword._abstract) && lookaheadType() === tt._class) { |
@@ -754,7 +754,24 @@ /* eslint max-len: 0 */ | ||
// Read an integer. We allow any valid digit, including hex digits, plus numeric separators, and | ||
// stop at any other character. | ||
/** | ||
* Read a decimal integer. Note that this can't be unified with the similar code | ||
* in readRadixNumber (which also handles hex digits) because "e" needs to be | ||
* the end of the integer so that we can properly handle scientific notation. | ||
*/ | ||
function readInt() { | ||
while (true) { | ||
const code = input.charCodeAt(state.pos); | ||
if ((code >= charCodes.digit0 && code <= charCodes.digit9) || code === charCodes.underscore) { | ||
state.pos++; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
function readRadixNumber() { | ||
state.pos += 2; // 0x | ||
// Walk to the end of the number, allowing hex digits. | ||
while (true) { | ||
const code = input.charCodeAt(state.pos); | ||
if ( | ||
@@ -771,25 +788,10 @@ (code >= charCodes.digit0 && code <= charCodes.digit9) || | ||
} | ||
} | ||
function readRadixNumber() { | ||
let isBigInt = false; | ||
const start = state.pos; | ||
state.pos += 2; // 0x | ||
readInt(); | ||
const nextChar = input.charCodeAt(state.pos); | ||
if (nextChar === charCodes.lowercaseN) { | ||
++state.pos; | ||
isBigInt = true; | ||
} else if (nextChar === charCodes.lowercaseM) { | ||
unexpected("Invalid decimal", start); | ||
} | ||
if (isBigInt) { | ||
finishToken(tt.bigint); | ||
return; | ||
} else { | ||
finishToken(tt.num); | ||
} | ||
finishToken(tt.num); | ||
} | ||
@@ -796,0 +798,0 @@ |
@@ -26,4 +26,6 @@ /* eslint max-len: 0 */ | ||
tsParseExportDeclaration, | ||
tsParseExportSpecifier, | ||
tsParseIdentifierStatement, | ||
tsParseImportEqualsDeclaration, | ||
tsParseImportSpecifier, | ||
tsParseMaybeDecoratorArguments, | ||
@@ -1063,8 +1065,15 @@ tsParseModifiers, | ||
} | ||
parseExportSpecifier(); | ||
} | ||
} | ||
function parseExportSpecifier() { | ||
if (isTypeScriptEnabled) { | ||
tsParseExportSpecifier(); | ||
return; | ||
} | ||
parseIdentifier(); | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ExportAccess; | ||
if (eatContextual(ContextualKeyword._as)) { | ||
parseIdentifier(); | ||
state.tokens[state.tokens.length - 1].identifierRole = IdentifierRole.ExportAccess; | ||
if (eatContextual(ContextualKeyword._as)) { | ||
parseIdentifier(); | ||
} | ||
} | ||
@@ -1169,2 +1178,6 @@ } | ||
function parseImportSpecifier() { | ||
if (isTypeScriptEnabled) { | ||
tsParseImportSpecifier(); | ||
return; | ||
} | ||
if (isFlowEnabled) { | ||
@@ -1171,0 +1184,0 @@ flowParseImportSpecifier(); |
@@ -12,2 +12,3 @@ | ||
} from "../util/getDeclarationInfo"; | ||
import getImportExportSpecifierInfo from "../util/getImportExportSpecifierInfo"; | ||
import shouldElideDefaultExport from "../util/shouldElideDefaultExport"; | ||
@@ -746,13 +747,9 @@ | ||
const localName = this.tokens.identifierName(); | ||
let exportedName; | ||
this.tokens.removeToken(); | ||
if (this.tokens.matchesContextual(ContextualKeyword._as)) { | ||
const specifierInfo = getImportExportSpecifierInfo(this.tokens); | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.removeToken(); | ||
exportedName = this.tokens.identifierName(); | ||
this.tokens.removeToken(); | ||
} else { | ||
exportedName = localName; | ||
} | ||
if (!this.shouldElideExportedIdentifier(localName)) { | ||
if (!specifierInfo.isType && !this.shouldElideExportedIdentifier(specifierInfo.leftName)) { | ||
const localName = specifierInfo.leftName; | ||
const exportedName = specifierInfo.rightName; | ||
const newLocalName = this.importProcessor.getIdentifierReplacement(localName); | ||
@@ -759,0 +756,0 @@ exportStatements.push(`exports.${exportedName} = ${newLocalName || localName};`); |
@@ -11,2 +11,3 @@ | ||
} from "../util/getDeclarationInfo"; | ||
import getImportExportSpecifierInfo from "../util/getImportExportSpecifierInfo"; | ||
import {getNonTypeIdentifiers} from "../util/getNonTypeIdentifiers"; | ||
@@ -194,64 +195,18 @@ import shouldElideDefaultExport from "../util/shouldElideDefaultExport"; | ||
while (!this.tokens.matches1(tt.braceR)) { | ||
if ( | ||
this.tokens.matches3(tt.name, tt.name, tt.comma) || | ||
this.tokens.matches3(tt.name, tt.name, tt.braceR) | ||
) { | ||
// type foo | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt.comma)) { | ||
const specifierInfo = getImportExportSpecifierInfo(this.tokens); | ||
if (specifierInfo.isType || this.isTypeName(specifierInfo.rightName)) { | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.removeToken(); | ||
} | ||
} else if ( | ||
this.tokens.matches5(tt.name, tt.name, tt.name, tt.name, tt.comma) || | ||
this.tokens.matches5(tt.name, tt.name, tt.name, tt.name, tt.braceR) | ||
) { | ||
// type foo as bar | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt.comma)) { | ||
this.tokens.removeToken(); | ||
} | ||
} else if ( | ||
this.tokens.matches2(tt.name, tt.comma) || | ||
this.tokens.matches2(tt.name, tt.braceR) | ||
) { | ||
// foo | ||
if (this.isTypeName(this.tokens.identifierName())) { | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt.comma)) { | ||
this.tokens.removeToken(); | ||
} | ||
} else { | ||
foundNonTypeImport = true; | ||
} else { | ||
foundNonTypeImport = true; | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.copyToken(); | ||
if (this.tokens.matches1(tt.comma)) { | ||
this.tokens.copyToken(); | ||
} | ||
} | ||
} else if ( | ||
this.tokens.matches4(tt.name, tt.name, tt.name, tt.comma) || | ||
this.tokens.matches4(tt.name, tt.name, tt.name, tt.braceR) | ||
) { | ||
// foo as bar | ||
if (this.isTypeName(this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2))) { | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(tt.comma)) { | ||
this.tokens.removeToken(); | ||
} | ||
} else { | ||
foundNonTypeImport = true; | ||
if (this.tokens.matches1(tt.comma)) { | ||
this.tokens.copyToken(); | ||
this.tokens.copyToken(); | ||
this.tokens.copyToken(); | ||
if (this.tokens.matches1(tt.comma)) { | ||
this.tokens.copyToken(); | ||
} | ||
} | ||
} else { | ||
throw new Error("Unexpected import form."); | ||
} | ||
@@ -318,11 +273,6 @@ } | ||
while (!this.tokens.matches1(tt.braceR)) { | ||
if (!this.tokens.matches1(tt.name)) { | ||
throw new Error("Expected identifier at the start of named export."); | ||
} | ||
if (this.shouldElideExportedName(this.tokens.identifierName())) { | ||
while ( | ||
!this.tokens.matches1(tt.comma) && | ||
!this.tokens.matches1(tt.braceR) && | ||
!this.tokens.isAtEnd() | ||
) { | ||
const specifierInfo = getImportExportSpecifierInfo(this.tokens); | ||
if (specifierInfo.isType || this.shouldElideExportedName(specifierInfo.leftName)) { | ||
// Type export, so remove all tokens, including any comma. | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.removeToken(); | ||
@@ -334,7 +284,4 @@ } | ||
} else { | ||
while ( | ||
!this.tokens.matches1(tt.comma) && | ||
!this.tokens.matches1(tt.braceR) && | ||
!this.tokens.isAtEnd() | ||
) { | ||
// Non-type export, so copy all tokens, including any comma. | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.copyToken(); | ||
@@ -353,3 +300,3 @@ } | ||
* ESM elides all imports with the rule that we only elide if we see that it's | ||
* a type and never see it as a value. This is in contract to CJS, which | ||
* a type and never see it as a value. This is in contrast to CJS, which | ||
* elides imports that are completely unknown. | ||
@@ -356,0 +303,0 @@ */ |
@@ -1,4 +0,4 @@ | ||
import {ContextualKeyword} from "../parser/tokenizer/keywords"; | ||
import {TokenType as tt} from "../parser/tokenizer/types"; | ||
import getImportExportSpecifierInfo from "./getImportExportSpecifierInfo"; | ||
@@ -68,12 +68,8 @@ /** | ||
// We care about the local name, which might be the first token, or if there's an "as", is the | ||
// one after that. | ||
let name = tokens.identifierNameAtIndex(index); | ||
index++; | ||
if (tokens.matchesContextualAtIndex(index, ContextualKeyword._as)) { | ||
index++; | ||
name = tokens.identifierNameAtIndex(index); | ||
index++; | ||
const specifierInfo = getImportExportSpecifierInfo(tokens, index); | ||
index = specifierInfo.endIndex; | ||
if (!specifierInfo.isType) { | ||
importedNames.add(specifierInfo.rightName); | ||
} | ||
importedNames.add(name); | ||
if (tokens.matches2AtIndex(index, tt.comma, tt.braceR)) { | ||
@@ -80,0 +76,0 @@ return; |
@@ -33,3 +33,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); | ||
function getVersion() { | ||
return "3.22.0"; | ||
return "3.23.0"; | ||
} exports.getVersion = getVersion; | ||
@@ -36,0 +36,0 @@ |
@@ -10,2 +10,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _index = require('../tokenizer/index'); | ||
@@ -1260,2 +1261,78 @@ var _keywords = require('../tokenizer/keywords'); | ||
/** | ||
* Parse a TS import specifier, which may be prefixed with "type" and may be of | ||
* the form `foo as bar`. | ||
* | ||
* The number of identifier-like tokens we see happens to be enough to uniquely | ||
* identify the form, so simply count the number of identifiers rather than | ||
* matching the words `type` or `as`. This is particularly important because | ||
* `type` and `as` could each actually be plain identifiers rather than | ||
* keywords. | ||
*/ | ||
function tsParseImportSpecifier() { | ||
_expression.parseIdentifier.call(void 0, ); | ||
if (_index.match.call(void 0, _types.TokenType.comma) || _index.match.call(void 0, _types.TokenType.braceR)) { | ||
// import {foo} | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ImportDeclaration; | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
if (_index.match.call(void 0, _types.TokenType.comma) || _index.match.call(void 0, _types.TokenType.braceR)) { | ||
// import {type foo} | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ImportDeclaration; | ||
_base.state.tokens[_base.state.tokens.length - 2].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 1].isType = true; | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
if (_index.match.call(void 0, _types.TokenType.comma) || _index.match.call(void 0, _types.TokenType.braceR)) { | ||
// import {foo as bar} | ||
_base.state.tokens[_base.state.tokens.length - 3].identifierRole = _index.IdentifierRole.ImportAccess; | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ImportDeclaration; | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
// import {type foo as bar} | ||
_base.state.tokens[_base.state.tokens.length - 3].identifierRole = _index.IdentifierRole.ImportAccess; | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ImportDeclaration; | ||
_base.state.tokens[_base.state.tokens.length - 4].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 3].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 2].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 1].isType = true; | ||
} exports.tsParseImportSpecifier = tsParseImportSpecifier; | ||
/** | ||
* Just like named import specifiers, export specifiers can have from 1 to 4 | ||
* tokens, inclusive, and the number of tokens determines the role of each token. | ||
*/ | ||
function tsParseExportSpecifier() { | ||
_expression.parseIdentifier.call(void 0, ); | ||
if (_index.match.call(void 0, _types.TokenType.comma) || _index.match.call(void 0, _types.TokenType.braceR)) { | ||
// export {foo} | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ExportAccess; | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
if (_index.match.call(void 0, _types.TokenType.comma) || _index.match.call(void 0, _types.TokenType.braceR)) { | ||
// export {type foo} | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ExportAccess; | ||
_base.state.tokens[_base.state.tokens.length - 2].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 1].isType = true; | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
if (_index.match.call(void 0, _types.TokenType.comma) || _index.match.call(void 0, _types.TokenType.braceR)) { | ||
// export {foo as bar} | ||
_base.state.tokens[_base.state.tokens.length - 3].identifierRole = _index.IdentifierRole.ExportAccess; | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
// export {type foo as bar} | ||
_base.state.tokens[_base.state.tokens.length - 3].identifierRole = _index.IdentifierRole.ExportAccess; | ||
_base.state.tokens[_base.state.tokens.length - 4].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 3].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 2].isType = true; | ||
_base.state.tokens[_base.state.tokens.length - 1].isType = true; | ||
} exports.tsParseExportSpecifier = tsParseExportSpecifier; | ||
function tsTryParseExportDefaultExpression() { | ||
@@ -1262,0 +1339,0 @@ if (_util.isContextual.call(void 0, _keywords.ContextualKeyword._abstract) && _index.lookaheadType.call(void 0, ) === _types.TokenType._class) { |
@@ -754,7 +754,24 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }/* eslint max-len: 0 */ | ||
// Read an integer. We allow any valid digit, including hex digits, plus numeric separators, and | ||
// stop at any other character. | ||
/** | ||
* Read a decimal integer. Note that this can't be unified with the similar code | ||
* in readRadixNumber (which also handles hex digits) because "e" needs to be | ||
* the end of the integer so that we can properly handle scientific notation. | ||
*/ | ||
function readInt() { | ||
while (true) { | ||
const code = _base.input.charCodeAt(_base.state.pos); | ||
if ((code >= _charcodes.charCodes.digit0 && code <= _charcodes.charCodes.digit9) || code === _charcodes.charCodes.underscore) { | ||
_base.state.pos++; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
function readRadixNumber() { | ||
_base.state.pos += 2; // 0x | ||
// Walk to the end of the number, allowing hex digits. | ||
while (true) { | ||
const code = _base.input.charCodeAt(_base.state.pos); | ||
if ( | ||
@@ -771,25 +788,10 @@ (code >= _charcodes.charCodes.digit0 && code <= _charcodes.charCodes.digit9) || | ||
} | ||
} | ||
function readRadixNumber() { | ||
let isBigInt = false; | ||
const start = _base.state.pos; | ||
_base.state.pos += 2; // 0x | ||
readInt(); | ||
const nextChar = _base.input.charCodeAt(_base.state.pos); | ||
if (nextChar === _charcodes.charCodes.lowercaseN) { | ||
++_base.state.pos; | ||
isBigInt = true; | ||
} else if (nextChar === _charcodes.charCodes.lowercaseM) { | ||
_util.unexpected.call(void 0, "Invalid decimal", start); | ||
} | ||
if (isBigInt) { | ||
finishToken(_types.TokenType.bigint); | ||
return; | ||
} else { | ||
finishToken(_types.TokenType.num); | ||
} | ||
finishToken(_types.TokenType.num); | ||
} | ||
@@ -796,0 +798,0 @@ |
@@ -37,2 +37,4 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});/* eslint max-len: 0 */ | ||
var _typescript = require('../plugins/typescript'); | ||
@@ -1063,10 +1065,17 @@ | ||
} | ||
parseExportSpecifier(); | ||
} | ||
} exports.parseExportSpecifiers = parseExportSpecifiers; | ||
function parseExportSpecifier() { | ||
if (_base.isTypeScriptEnabled) { | ||
_typescript.tsParseExportSpecifier.call(void 0, ); | ||
return; | ||
} | ||
_expression.parseIdentifier.call(void 0, ); | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _tokenizer.IdentifierRole.ExportAccess; | ||
if (_util.eatContextual.call(void 0, _keywords.ContextualKeyword._as)) { | ||
_expression.parseIdentifier.call(void 0, ); | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _tokenizer.IdentifierRole.ExportAccess; | ||
if (_util.eatContextual.call(void 0, _keywords.ContextualKeyword._as)) { | ||
_expression.parseIdentifier.call(void 0, ); | ||
} | ||
} | ||
} exports.parseExportSpecifiers = parseExportSpecifiers; | ||
} | ||
@@ -1169,2 +1178,6 @@ // Parses import declaration. | ||
function parseImportSpecifier() { | ||
if (_base.isTypeScriptEnabled) { | ||
_typescript.tsParseImportSpecifier.call(void 0, ); | ||
return; | ||
} | ||
if (_base.isFlowEnabled) { | ||
@@ -1171,0 +1184,0 @@ _flow.flowParseImportSpecifier.call(void 0, ); |
@@ -12,2 +12,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _getDeclarationInfo = require('../util/getDeclarationInfo'); var _getDeclarationInfo2 = _interopRequireDefault(_getDeclarationInfo); | ||
var _getImportExportSpecifierInfo = require('../util/getImportExportSpecifierInfo'); var _getImportExportSpecifierInfo2 = _interopRequireDefault(_getImportExportSpecifierInfo); | ||
var _shouldElideDefaultExport = require('../util/shouldElideDefaultExport'); var _shouldElideDefaultExport2 = _interopRequireDefault(_shouldElideDefaultExport); | ||
@@ -746,13 +747,9 @@ | ||
const localName = this.tokens.identifierName(); | ||
let exportedName; | ||
this.tokens.removeToken(); | ||
if (this.tokens.matchesContextual(_keywords.ContextualKeyword._as)) { | ||
const specifierInfo = _getImportExportSpecifierInfo2.default.call(void 0, this.tokens); | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.removeToken(); | ||
exportedName = this.tokens.identifierName(); | ||
this.tokens.removeToken(); | ||
} else { | ||
exportedName = localName; | ||
} | ||
if (!this.shouldElideExportedIdentifier(localName)) { | ||
if (!specifierInfo.isType && !this.shouldElideExportedIdentifier(specifierInfo.leftName)) { | ||
const localName = specifierInfo.leftName; | ||
const exportedName = specifierInfo.rightName; | ||
const newLocalName = this.importProcessor.getIdentifierReplacement(localName); | ||
@@ -759,0 +756,0 @@ exportStatements.push(`exports.${exportedName} = ${newLocalName || localName};`); |
@@ -11,2 +11,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _getDeclarationInfo = require('../util/getDeclarationInfo'); var _getDeclarationInfo2 = _interopRequireDefault(_getDeclarationInfo); | ||
var _getImportExportSpecifierInfo = require('../util/getImportExportSpecifierInfo'); var _getImportExportSpecifierInfo2 = _interopRequireDefault(_getImportExportSpecifierInfo); | ||
var _getNonTypeIdentifiers = require('../util/getNonTypeIdentifiers'); | ||
@@ -194,64 +195,18 @@ var _shouldElideDefaultExport = require('../util/shouldElideDefaultExport'); var _shouldElideDefaultExport2 = _interopRequireDefault(_shouldElideDefaultExport); | ||
while (!this.tokens.matches1(_types.TokenType.braceR)) { | ||
if ( | ||
this.tokens.matches3(_types.TokenType.name, _types.TokenType.name, _types.TokenType.comma) || | ||
this.tokens.matches3(_types.TokenType.name, _types.TokenType.name, _types.TokenType.braceR) | ||
) { | ||
// type foo | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
const specifierInfo = _getImportExportSpecifierInfo2.default.call(void 0, this.tokens); | ||
if (specifierInfo.isType || this.isTypeName(specifierInfo.rightName)) { | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.removeToken(); | ||
} | ||
} else if ( | ||
this.tokens.matches5(_types.TokenType.name, _types.TokenType.name, _types.TokenType.name, _types.TokenType.name, _types.TokenType.comma) || | ||
this.tokens.matches5(_types.TokenType.name, _types.TokenType.name, _types.TokenType.name, _types.TokenType.name, _types.TokenType.braceR) | ||
) { | ||
// type foo as bar | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
this.tokens.removeToken(); | ||
} | ||
} else if ( | ||
this.tokens.matches2(_types.TokenType.name, _types.TokenType.comma) || | ||
this.tokens.matches2(_types.TokenType.name, _types.TokenType.braceR) | ||
) { | ||
// foo | ||
if (this.isTypeName(this.tokens.identifierName())) { | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
this.tokens.removeToken(); | ||
} | ||
} else { | ||
foundNonTypeImport = true; | ||
} else { | ||
foundNonTypeImport = true; | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.copyToken(); | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
this.tokens.copyToken(); | ||
} | ||
} | ||
} else if ( | ||
this.tokens.matches4(_types.TokenType.name, _types.TokenType.name, _types.TokenType.name, _types.TokenType.comma) || | ||
this.tokens.matches4(_types.TokenType.name, _types.TokenType.name, _types.TokenType.name, _types.TokenType.braceR) | ||
) { | ||
// foo as bar | ||
if (this.isTypeName(this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2))) { | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
this.tokens.removeToken(); | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
this.tokens.removeToken(); | ||
} | ||
} else { | ||
foundNonTypeImport = true; | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
this.tokens.copyToken(); | ||
this.tokens.copyToken(); | ||
this.tokens.copyToken(); | ||
if (this.tokens.matches1(_types.TokenType.comma)) { | ||
this.tokens.copyToken(); | ||
} | ||
} | ||
} else { | ||
throw new Error("Unexpected import form."); | ||
} | ||
@@ -318,11 +273,6 @@ } | ||
while (!this.tokens.matches1(_types.TokenType.braceR)) { | ||
if (!this.tokens.matches1(_types.TokenType.name)) { | ||
throw new Error("Expected identifier at the start of named export."); | ||
} | ||
if (this.shouldElideExportedName(this.tokens.identifierName())) { | ||
while ( | ||
!this.tokens.matches1(_types.TokenType.comma) && | ||
!this.tokens.matches1(_types.TokenType.braceR) && | ||
!this.tokens.isAtEnd() | ||
) { | ||
const specifierInfo = _getImportExportSpecifierInfo2.default.call(void 0, this.tokens); | ||
if (specifierInfo.isType || this.shouldElideExportedName(specifierInfo.leftName)) { | ||
// Type export, so remove all tokens, including any comma. | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.removeToken(); | ||
@@ -334,7 +284,4 @@ } | ||
} else { | ||
while ( | ||
!this.tokens.matches1(_types.TokenType.comma) && | ||
!this.tokens.matches1(_types.TokenType.braceR) && | ||
!this.tokens.isAtEnd() | ||
) { | ||
// Non-type export, so copy all tokens, including any comma. | ||
while (this.tokens.currentIndex() < specifierInfo.endIndex) { | ||
this.tokens.copyToken(); | ||
@@ -353,3 +300,3 @@ } | ||
* ESM elides all imports with the rule that we only elide if we see that it's | ||
* a type and never see it as a value. This is in contract to CJS, which | ||
* a type and never see it as a value. This is in contrast to CJS, which | ||
* elides imports that are completely unknown. | ||
@@ -356,0 +303,0 @@ */ |
@@ -19,2 +19,18 @@ import { ContextualKeyword } from "../tokenizer/keywords"; | ||
export declare function tsTryParseExport(): boolean; | ||
/** | ||
* Parse a TS import specifier, which may be prefixed with "type" and may be of | ||
* the form `foo as bar`. | ||
* | ||
* The number of identifier-like tokens we see happens to be enough to uniquely | ||
* identify the form, so simply count the number of identifiers rather than | ||
* matching the words `type` or `as`. This is particularly important because | ||
* `type` and `as` could each actually be plain identifiers rather than | ||
* keywords. | ||
*/ | ||
export declare function tsParseImportSpecifier(): void; | ||
/** | ||
* Just like named import specifiers, export specifiers can have from 1 to 4 | ||
* tokens, inclusive, and the number of tokens determines the role of each token. | ||
*/ | ||
export declare function tsParseExportSpecifier(): void; | ||
export declare function tsTryParseExportDefaultExpression(): boolean; | ||
@@ -21,0 +37,0 @@ export declare function tsTryParseStatementContent(): boolean; |
@@ -37,3 +37,3 @@ import type { Options } from "../index"; | ||
* ESM elides all imports with the rule that we only elide if we see that it's | ||
* a type and never see it as a value. This is in contract to CJS, which | ||
* a type and never see it as a value. This is in contrast to CJS, which | ||
* elides imports that are completely unknown. | ||
@@ -40,0 +40,0 @@ */ |
@@ -1,4 +0,4 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _keywords = require('../parser/tokenizer/keywords'); | ||
var _types = require('../parser/tokenizer/types'); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _types = require('../parser/tokenizer/types'); | ||
var _getImportExportSpecifierInfo = require('./getImportExportSpecifierInfo'); var _getImportExportSpecifierInfo2 = _interopRequireDefault(_getImportExportSpecifierInfo); | ||
@@ -68,12 +68,8 @@ /** | ||
// We care about the local name, which might be the first token, or if there's an "as", is the | ||
// one after that. | ||
let name = tokens.identifierNameAtIndex(index); | ||
index++; | ||
if (tokens.matchesContextualAtIndex(index, _keywords.ContextualKeyword._as)) { | ||
index++; | ||
name = tokens.identifierNameAtIndex(index); | ||
index++; | ||
const specifierInfo = _getImportExportSpecifierInfo2.default.call(void 0, tokens, index); | ||
index = specifierInfo.endIndex; | ||
if (!specifierInfo.isType) { | ||
importedNames.add(specifierInfo.rightName); | ||
} | ||
importedNames.add(name); | ||
if (tokens.matches2AtIndex(index, _types.TokenType.comma, _types.TokenType.braceR)) { | ||
@@ -80,0 +76,0 @@ return; |
{ | ||
"name": "sucrase", | ||
"version": "3.22.0", | ||
"version": "3.23.0", | ||
"description": "Super-fast alternative to Babel for when you can target modern JS runtimes", | ||
@@ -64,3 +64,3 @@ "author": "Alan Pierce <alangpierce@gmail.com>", | ||
"prettier": "^2.6.2", | ||
"sucrase": "^3.21.1", | ||
"sucrase": "^3.22.0", | ||
"test262-harness": "^10.0.0", | ||
@@ -67,0 +67,0 @@ "ts-interface-builder": "^0.3.3", |
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
1015985
183
26011