Comparing version 3.16.0 to 3.17.0
@@ -0,1 +1,16 @@ | ||
# 3.17.0 (2020-12-29) | ||
* Fix incorrect export removal when exporting a variable defined using a | ||
destructure declaration. ([#564]) | ||
* Add support for new type syntax in TypeScript 4.1: template interpolations in | ||
string literal types and `as` to remap keys in mapped types. Also add parsing | ||
for static blocks and pass them through in the output. ([#567]) | ||
* Allow passing `pirates` options `matcher` and `ignoreNodeModules` when | ||
directly calling `registerJS` and related functions. ([#571], [#573]) | ||
(Gordon Leigh) | ||
* Properly emit private class field declarations in the output code so that | ||
private fields can be used when they're supported by the target JS engine. | ||
([#574]) | ||
* Fix parse error when a method or field has the name `declare`. ([#575]) | ||
# 3.16.0 (2020-10-12) | ||
@@ -302,1 +317,7 @@ | ||
[#556]: https://github.com/alangpierce/sucrase/pull/556 | ||
[#564]: https://github.com/alangpierce/sucrase/pull/564 | ||
[#567]: https://github.com/alangpierce/sucrase/pull/567 | ||
[#571]: https://github.com/alangpierce/sucrase/pull/571 | ||
[#573]: https://github.com/alangpierce/sucrase/pull/573 | ||
[#574]: https://github.com/alangpierce/sucrase/pull/574 | ||
[#575]: https://github.com/alangpierce/sucrase/pull/575 |
@@ -9,2 +9,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _index = require('../tokenizer/index'); | ||
@@ -63,2 +64,13 @@ var _keywords = require('../tokenizer/keywords'); | ||
function isLiteralPropertyName() { | ||
return ( | ||
_index.match.call(void 0, _types.TokenType.name) || | ||
Boolean(_base.state.type & _types.TokenType.IS_KEYWORD) || | ||
_index.match.call(void 0, _types.TokenType.string) || | ||
_index.match.call(void 0, _types.TokenType.num) || | ||
_index.match.call(void 0, _types.TokenType.bigint) || | ||
_index.match.call(void 0, _types.TokenType.decimal) | ||
); | ||
} | ||
function tsNextTokenCanFollowModifier() { | ||
@@ -73,9 +85,9 @@ // Note: TypeScript's implementation is much more complicated because | ||
const canFollowModifier = | ||
!_util.hasPrecedingLineBreak.call(void 0, ) && | ||
!_index.match.call(void 0, _types.TokenType.parenL) && | ||
!_index.match.call(void 0, _types.TokenType.parenR) && | ||
!_index.match.call(void 0, _types.TokenType.colon) && | ||
!_index.match.call(void 0, _types.TokenType.eq) && | ||
!_index.match.call(void 0, _types.TokenType.question) && | ||
!_index.match.call(void 0, _types.TokenType.bang); | ||
(_index.match.call(void 0, _types.TokenType.bracketL) || | ||
_index.match.call(void 0, _types.TokenType.braceL) || | ||
_index.match.call(void 0, _types.TokenType.star) || | ||
_index.match.call(void 0, _types.TokenType.ellipsis) || | ||
_index.match.call(void 0, _types.TokenType.hash) || | ||
isLiteralPropertyName()) && | ||
!_util.hasPrecedingLineBreak.call(void 0, ); | ||
@@ -358,2 +370,5 @@ if (canFollowModifier) { | ||
tsParseMappedTypeParameter(); | ||
if (_util.eatContextual.call(void 0, _keywords.ContextualKeyword._as)) { | ||
tsParseType(); | ||
} | ||
_util.expect.call(void 0, _types.TokenType.bracketR); | ||
@@ -403,2 +418,18 @@ if (_index.match.call(void 0, _types.TokenType.plus) || _index.match.call(void 0, _types.TokenType.minus)) { | ||
function tsParseTemplateLiteralType() { | ||
// Finish `, read quasi | ||
_index.nextTemplateToken.call(void 0, ); | ||
// Finish quasi, read ${ | ||
_index.nextTemplateToken.call(void 0, ); | ||
while (!_index.match.call(void 0, _types.TokenType.backQuote) && !_base.state.error) { | ||
_util.expect.call(void 0, _types.TokenType.dollarBraceL); | ||
tsParseType(); | ||
// Finish }, read quasi | ||
_index.nextTemplateToken.call(void 0, ); | ||
// Finish quasi, read either ${ or ` | ||
_index.nextTemplateToken.call(void 0, ); | ||
} | ||
_index.next.call(void 0, ); | ||
} | ||
var FunctionType; (function (FunctionType) { | ||
@@ -464,3 +495,3 @@ const TSFunctionType = 0; FunctionType[FunctionType["TSFunctionType"] = TSFunctionType] = "TSFunctionType"; | ||
case _types.TokenType.backQuote: | ||
_expression.parseTemplate.call(void 0, ); | ||
tsParseTemplateLiteralType(); | ||
return; | ||
@@ -467,0 +498,0 @@ default: |
@@ -479,7 +479,2 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }/* eslint max-len: 0 */ | ||
function readToken_lt_gt(code) { | ||
// Avoid right-shift for things like Array<Array<string>>. | ||
if (code === _charcodes.charCodes.greaterThan && _base.state.isType) { | ||
finishOp(_types.TokenType.greaterThan, 1); | ||
return; | ||
} | ||
const nextChar = _base.input.charCodeAt(_base.state.pos + 1); | ||
@@ -496,2 +491,7 @@ | ||
} | ||
// Avoid right-shift for things like Array<Array<string>>. | ||
if (code === _charcodes.charCodes.greaterThan && _base.state.isType) { | ||
finishOp(_types.TokenType.greaterThan, 1); | ||
return; | ||
} | ||
finishOp(_types.TokenType.bitShift, size); | ||
@@ -498,0 +498,0 @@ return; |
@@ -524,3 +524,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});/* eslint max-len: 0 */ | ||
_index3.next.call(void 0, ); | ||
_statement.parseBlock.call(void 0, false); | ||
_statement.parseBlock.call(void 0, ); | ||
return false; | ||
@@ -841,9 +841,15 @@ } | ||
// transform it on access, so mark it as a normal object shorthand. | ||
let identifierRole; | ||
if (isPattern) { | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = isBlockScope | ||
? _index3.IdentifierRole.ObjectShorthandBlockScopedDeclaration | ||
: _index3.IdentifierRole.ObjectShorthandFunctionScopedDeclaration; | ||
if (_base.state.scopeDepth === 0) { | ||
identifierRole = _index3.IdentifierRole.ObjectShorthandTopLevelDeclaration; | ||
} else if (isBlockScope) { | ||
identifierRole = _index3.IdentifierRole.ObjectShorthandBlockScopedDeclaration; | ||
} else { | ||
identifierRole = _index3.IdentifierRole.ObjectShorthandFunctionScopedDeclaration; | ||
} | ||
} else { | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index3.IdentifierRole.ObjectShorthand; | ||
identifierRole = _index3.IdentifierRole.ObjectShorthand; | ||
} | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = identifierRole; | ||
@@ -932,3 +938,3 @@ // Regardless of whether we know this to be a pattern or if we're in an ambiguous context, allow | ||
} else { | ||
_statement.parseBlock.call(void 0, true /* allowDirectives */, true /* isFunctionScope */, funcContextId); | ||
_statement.parseBlock.call(void 0, true /* isFunctionScope */, funcContextId); | ||
} | ||
@@ -935,0 +941,0 @@ } exports.parseFunctionBody = parseFunctionBody; |
@@ -42,9 +42,11 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _flow = require('../plugins/flow'); | ||
function markPriorBindingIdentifier(isBlockScope) { | ||
let identifierRole; | ||
if (_base.state.scopeDepth === 0) { | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.TopLevelDeclaration; | ||
identifierRole = _index.IdentifierRole.TopLevelDeclaration; | ||
} else if (isBlockScope) { | ||
identifierRole = _index.IdentifierRole.BlockScopedDeclaration; | ||
} else { | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = isBlockScope | ||
? _index.IdentifierRole.BlockScopedDeclaration | ||
: _index.IdentifierRole.FunctionScopedDeclaration; | ||
identifierRole = _index.IdentifierRole.FunctionScopedDeclaration; | ||
} | ||
_base.state.tokens[_base.state.tokens.length - 1].identifierRole = identifierRole; | ||
} exports.markPriorBindingIdentifier = markPriorBindingIdentifier; | ||
@@ -51,0 +53,0 @@ |
@@ -8,3 +8,3 @@ import { File } from "../index"; | ||
export declare function parseVarStatement(kind: TokenType): void; | ||
export declare function parseBlock(allowDirectives?: boolean, isFunctionScope?: boolean, contextId?: number): void; | ||
export declare function parseBlock(isFunctionScope?: boolean, contextId?: number): void; | ||
export declare function parseBlockBody(end: TokenType): void; | ||
@@ -11,0 +11,0 @@ export declare function parseFunction(functionStart: number, isStatement: boolean, optionalId?: boolean): void; |
@@ -36,2 +36,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});/* eslint max-len: 0 */ | ||
var _typescript = require('../plugins/typescript'); | ||
@@ -485,11 +486,4 @@ | ||
// Parse a semicolon-enclosed block of statements, handling `"use | ||
// strict"` declarations when `allowStrict` is true (used for | ||
// function bodies). | ||
function parseBlock( | ||
allowDirectives = false, | ||
isFunctionScope = false, | ||
contextId = 0, | ||
) { | ||
// Parse a semicolon-enclosed block of statements. | ||
function parseBlock(isFunctionScope = false, contextId = 0) { | ||
const startTokenIndex = _base.state.tokens.length; | ||
@@ -704,5 +698,5 @@ _base.state.scopeDepth++; | ||
if (_base.isTypeScriptEnabled) { | ||
_util.eatContextual.call(void 0, _keywords.ContextualKeyword._declare); | ||
_typescript.tsParseModifier.call(void 0, [_keywords.ContextualKeyword._declare]); | ||
_typescript.tsParseAccessModifier.call(void 0, ); | ||
_util.eatContextual.call(void 0, _keywords.ContextualKeyword._declare); | ||
_typescript.tsParseModifier.call(void 0, [_keywords.ContextualKeyword._declare]); | ||
} | ||
@@ -722,2 +716,10 @@ let isStatic = false; | ||
isStatic = true; | ||
if (_tokenizer.match.call(void 0, _types.TokenType.braceL)) { | ||
// This is a static block. Mark the word "static" with the class context ID for class element | ||
// detection and parse as a regular block. | ||
_base.state.tokens[_base.state.tokens.length - 1].contextId = classContextId; | ||
parseBlock(); | ||
return; | ||
} | ||
} | ||
@@ -724,0 +726,0 @@ |
import { Options } from "./index"; | ||
export declare function addHook(extension: string, options: Options): void; | ||
export declare function registerJS(): void; | ||
export declare function registerJSX(): void; | ||
export declare function registerTS(): void; | ||
export declare function registerTSX(): void; | ||
export declare function registerTSLegacyModuleInterop(): void; | ||
export declare function registerTSXLegacyModuleInterop(): void; | ||
export declare function registerAll(): void; | ||
export interface HookOptions { | ||
matcher?: (code: string) => boolean; | ||
ignoreNodeModules?: boolean; | ||
} | ||
export declare function addHook(extension: string, options: Options, hookOptions?: HookOptions): void; | ||
export declare function registerJS(hookOptions?: HookOptions): void; | ||
export declare function registerJSX(hookOptions?: HookOptions): void; | ||
export declare function registerTS(hookOptions?: HookOptions): void; | ||
export declare function registerTSX(hookOptions?: HookOptions): void; | ||
export declare function registerTSLegacyModuleInterop(hookOptions?: HookOptions): void; | ||
export declare function registerTSXLegacyModuleInterop(hookOptions?: HookOptions): void; | ||
export declare function registerAll(hookOptions?: HookOptions): void; |
@@ -1,7 +0,11 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// @ts-ignore: no types available. | ||
var _pirates = require('pirates'); var pirates = _interopRequireWildcard(_pirates); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _pirates = require('pirates'); var pirates = _interopRequireWildcard(_pirates); | ||
var _index = require('./index'); | ||
function addHook(extension, options) { | ||
function addHook(extension, options, hookOptions) { | ||
pirates.addHook( | ||
@@ -18,41 +22,49 @@ (code, filePath) => { | ||
}, | ||
{exts: [extension]}, | ||
{...hookOptions, exts: [extension]}, | ||
); | ||
} exports.addHook = addHook; | ||
function registerJS() { | ||
addHook(".js", {transforms: ["imports", "flow", "jsx"]}); | ||
function registerJS(hookOptions) { | ||
addHook(".js", {transforms: ["imports", "flow", "jsx"]}, hookOptions); | ||
} exports.registerJS = registerJS; | ||
function registerJSX() { | ||
addHook(".jsx", {transforms: ["imports", "flow", "jsx"]}); | ||
function registerJSX(hookOptions) { | ||
addHook(".jsx", {transforms: ["imports", "flow", "jsx"]}, hookOptions); | ||
} exports.registerJSX = registerJSX; | ||
function registerTS() { | ||
addHook(".ts", {transforms: ["imports", "typescript"]}); | ||
function registerTS(hookOptions) { | ||
addHook(".ts", {transforms: ["imports", "typescript"]}, hookOptions); | ||
} exports.registerTS = registerTS; | ||
function registerTSX() { | ||
addHook(".tsx", {transforms: ["imports", "typescript", "jsx"]}); | ||
function registerTSX(hookOptions) { | ||
addHook(".tsx", {transforms: ["imports", "typescript", "jsx"]}, hookOptions); | ||
} exports.registerTSX = registerTSX; | ||
function registerTSLegacyModuleInterop() { | ||
addHook(".ts", { | ||
transforms: ["imports", "typescript"], | ||
enableLegacyTypeScriptModuleInterop: true, | ||
}); | ||
function registerTSLegacyModuleInterop(hookOptions) { | ||
addHook( | ||
".ts", | ||
{ | ||
transforms: ["imports", "typescript"], | ||
enableLegacyTypeScriptModuleInterop: true, | ||
}, | ||
hookOptions, | ||
); | ||
} exports.registerTSLegacyModuleInterop = registerTSLegacyModuleInterop; | ||
function registerTSXLegacyModuleInterop() { | ||
addHook(".tsx", { | ||
transforms: ["imports", "typescript", "jsx"], | ||
enableLegacyTypeScriptModuleInterop: true, | ||
}); | ||
function registerTSXLegacyModuleInterop(hookOptions) { | ||
addHook( | ||
".tsx", | ||
{ | ||
transforms: ["imports", "typescript", "jsx"], | ||
enableLegacyTypeScriptModuleInterop: true, | ||
}, | ||
hookOptions, | ||
); | ||
} exports.registerTSXLegacyModuleInterop = registerTSXLegacyModuleInterop; | ||
function registerAll() { | ||
registerJS(); | ||
registerJSX(); | ||
registerTS(); | ||
registerTSX(); | ||
function registerAll(hookOptions) { | ||
registerJS(hookOptions); | ||
registerJSX(hookOptions); | ||
registerTS(hookOptions); | ||
registerTSX(hookOptions); | ||
} exports.registerAll = registerAll; |
@@ -82,2 +82,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
let isStatic = false; | ||
let isESPrivate = false; | ||
while (isAccessModifier(tokens.currentToken())) { | ||
@@ -87,4 +88,17 @@ if (tokens.matches1(_types.TokenType._static)) { | ||
} | ||
if (tokens.matches1(_types.TokenType.hash)) { | ||
isESPrivate = true; | ||
} | ||
tokens.nextToken(); | ||
} | ||
if (isStatic && tokens.matches1(_types.TokenType.braceL)) { | ||
// This is a static block, so don't process it in any special way. | ||
skipToNextClassElement(tokens, classContextId); | ||
continue; | ||
} | ||
if (isESPrivate) { | ||
// Sucrase doesn't attempt to transpile private fields; just leave them as-is. | ||
skipToNextClassElement(tokens, classContextId); | ||
continue; | ||
} | ||
if ( | ||
@@ -97,14 +111,8 @@ tokens.matchesContextual(_keywords.ContextualKeyword._constructor) && | ||
} | ||
const nameStartIndex = tokens.currentIndex(); | ||
skipFieldName(tokens); | ||
if (tokens.matches1(_types.TokenType.lessThan) || tokens.matches1(_types.TokenType.parenL)) { | ||
// This is a method, so just skip to the next method/field. To do that, we seek forward to | ||
// the next start of a class name (either an open bracket or an identifier, or the closing | ||
// curly brace), then seek backward to include any access modifiers. | ||
while (tokens.currentToken().contextId !== classContextId) { | ||
tokens.nextToken(); | ||
} | ||
while (isAccessModifier(tokens.tokenAtRelativeIndex(-1))) { | ||
tokens.previousToken(); | ||
} | ||
// This is a method, so nothing to process. | ||
skipToNextClassElement(tokens, classContextId); | ||
continue; | ||
@@ -161,2 +169,19 @@ } | ||
/** | ||
* Move the token processor to the next method/field in the class. | ||
* | ||
* To do that, we seek forward to the next start of a class name (either an open | ||
* bracket or an identifier, or the closing curly brace), then seek backward to | ||
* include any access modifiers. | ||
*/ | ||
function skipToNextClassElement(tokens, classContextId) { | ||
tokens.nextToken(); | ||
while (tokens.currentToken().contextId !== classContextId) { | ||
tokens.nextToken(); | ||
} | ||
while (isAccessModifier(tokens.tokenAtRelativeIndex(-1))) { | ||
tokens.previousToken(); | ||
} | ||
} | ||
function processClassHeader(tokens) { | ||
@@ -271,2 +296,3 @@ const classToken = tokens.currentToken(); | ||
_types.TokenType._declare, | ||
_types.TokenType.hash, | ||
].includes(token.type); | ||
@@ -273,0 +299,0 @@ } |
{ | ||
"name": "sucrase", | ||
"version": "3.16.0", | ||
"version": "3.17.0", | ||
"description": "Super-fast alternative to Babel for when you can target modern JS runtimes", | ||
@@ -73,3 +73,3 @@ "author": "Alan Pierce <alangpierce@gmail.com>", | ||
"prettier": "^2.0.5", | ||
"sucrase": "^3.15.0", | ||
"sucrase": "^3.16.0", | ||
"test262-harness": "^6.5.0", | ||
@@ -76,0 +76,0 @@ "ts-interface-builder": "^0.2.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
950573
24169