Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sucrase

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sucrase - npm Package Compare versions

Comparing version 3.18.2 to 3.19.0

7

CHANGELOG.md

@@ -0,1 +1,5 @@

# 3.19.0 (2021-06-23)
* Add option to disable ES transforms. ([#623], [#624], [#625]) (Denys Kniazevych, Alan Pierce)
# 3.18.2 (2021-06-07)

@@ -353,1 +357,4 @@

[#621]: https://github.com/alangpierce/sucrase/pull/621
[#623]: https://github.com/alangpierce/sucrase/pull/623
[#624]: https://github.com/alangpierce/sucrase/pull/624
[#625]: https://github.com/alangpierce/sucrase/pull/625

9

dist/index.js

@@ -88,2 +88,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);

const isFlowEnabled = options.transforms.includes("flow");
const disableESTransforms = options.disableESTransforms === true;
const file = _parser.parse.call(void 0, code, isJSXEnabled, isTypeScriptEnabled, isFlowEnabled);

@@ -95,3 +96,9 @@ const tokens = file.tokens;

const helperManager = new (0, _HelperManager.HelperManager)(nameManager);
const tokenProcessor = new (0, _TokenProcessor2.default)(code, tokens, isFlowEnabled, helperManager);
const tokenProcessor = new (0, _TokenProcessor2.default)(
code,
tokens,
isFlowEnabled,
disableESTransforms,
helperManager,
);
const enableLegacyTypeScriptModuleInterop = Boolean(options.enableLegacyTypeScriptModuleInterop);

@@ -98,0 +105,0 @@

@@ -29,2 +29,3 @@ "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; } }/**

production: t.opt("boolean"),
disableESTransforms: t.opt("boolean"),
}); exports.Options = Options;

@@ -31,0 +32,0 @@

@@ -41,3 +41,8 @@ export declare type Transform = "jsx" | "typescript" | "flow" | "imports" | "react-hot-loader" | "jest";

production?: boolean;
/**
* Opts out ES syntax transformations, like optional chaining, nullish coalescing, numeric
* separators, etc.
*/
disableESTransforms?: boolean;
}
export declare function validateOptions(options: Options): void;

@@ -51,4 +51,9 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _tsinterfacechecker = require('ts-interface-checker');

function validateOptions(options) {
OptionsChecker.strictCheck(options);
} exports.validateOptions = validateOptions;

@@ -701,2 +701,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});/* eslint max-len: 0 */

_index.next.call(void 0, );
_base.state.tokens[_base.state.tokens.length - 1].isType = true;
}

@@ -703,0 +704,0 @@ } exports.flowParseVariance = flowParseVariance;

3

dist/TokenProcessor.d.ts

@@ -13,6 +13,7 @@ import type { HelperManager } from "./HelperManager";

readonly isFlowEnabled: boolean;
readonly disableESTransforms: boolean;
readonly helperManager: HelperManager;
private resultCode;
private tokenIndex;
constructor(code: string, tokens: Array<Token>, isFlowEnabled: boolean, helperManager: HelperManager);
constructor(code: string, tokens: Array<Token>, isFlowEnabled: boolean, disableESTransforms: boolean, helperManager: HelperManager);
/**

@@ -19,0 +20,0 @@ * Make a new TokenProcessor for things like lookahead.

@@ -20,4 +20,5 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

isFlowEnabled,
disableESTransforms,
helperManager,
) {;this.code = code;this.tokens = tokens;this.isFlowEnabled = isFlowEnabled;this.helperManager = helperManager;TokenProcessor.prototype.__init.call(this);TokenProcessor.prototype.__init2.call(this);}
) {;this.code = code;this.tokens = tokens;this.isFlowEnabled = isFlowEnabled;this.disableESTransforms = disableESTransforms;this.helperManager = helperManager;TokenProcessor.prototype.__init.call(this);TokenProcessor.prototype.__init2.call(this);}

@@ -214,2 +215,5 @@ /**

}
if (this.disableESTransforms) {
return;
}
if (token.numNullishCoalesceStarts) {

@@ -247,6 +251,6 @@ for (let i = 0; i < token.numNullishCoalesceStarts; i++) {

const token = this.currentToken();
if (token.isOptionalChainEnd) {
if (token.isOptionalChainEnd && !this.disableESTransforms) {
this.resultCode += "])";
}
if (token.numNullishCoalesceEnds) {
if (token.numNullishCoalesceEnds && !this.disableESTransforms) {
for (let i = 0; i < token.numNullishCoalesceEnds; i++) {

@@ -253,0 +257,0 @@ this.resultCode += "))";

@@ -10,2 +10,3 @@ import type { Options, SucraseContext, Transform } from "../index";

private isReactHotLoaderTransformEnabled;
private disableESTransforms;
private helperManager;

@@ -12,0 +13,0 @@ constructor(sucraseContext: SucraseContext, transforms: Array<Transform>, enableLegacyBabel5ModuleInterop: boolean, options: Options);

@@ -29,2 +29,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -43,8 +44,12 @@ constructor(

this.isReactHotLoaderTransformEnabled = transforms.includes("react-hot-loader");
this.disableESTransforms = Boolean(options.disableESTransforms);
this.transformers.push(
new (0, _OptionalChainingNullishTransformer2.default)(tokenProcessor, this.nameManager),
);
this.transformers.push(new (0, _NumericSeparatorTransformer2.default)(tokenProcessor));
this.transformers.push(new (0, _OptionalCatchBindingTransformer2.default)(tokenProcessor, this.nameManager));
if (!options.disableESTransforms) {
this.transformers.push(
new (0, _OptionalChainingNullishTransformer2.default)(tokenProcessor, this.nameManager),
);
this.transformers.push(new (0, _NumericSeparatorTransformer2.default)(tokenProcessor));
this.transformers.push(new (0, _OptionalCatchBindingTransformer2.default)(tokenProcessor, this.nameManager));
}
if (transforms.includes("jsx")) {

@@ -195,3 +200,3 @@ this.transformers.push(

processClass() {
const classInfo = _getClassInfo2.default.call(void 0, this, this.tokens, this.nameManager);
const classInfo = _getClassInfo2.default.call(void 0, this, this.tokens, this.nameManager, this.disableESTransforms);

@@ -198,0 +203,0 @@ // Both static and instance initializers need a class name to use to invoke the initializer, so

@@ -34,2 +34,2 @@ import type NameManager from "../NameManager";

*/
export default function getClassInfo(rootTransformer: RootTransformer, tokens: TokenProcessor, nameManager: NameManager): ClassInfo;
export default function getClassInfo(rootTransformer: RootTransformer, tokens: TokenProcessor, nameManager: NameManager, disableESTransforms: boolean): ClassInfo;

@@ -52,2 +52,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});

nameManager,
disableESTransforms,
) {

@@ -75,3 +76,5 @@ const snapshot = tokens.snapshot();

} else if (tokens.matches1(_types.TokenType.semi)) {
rangesToRemove.push({start: tokens.currentIndex(), end: tokens.currentIndex() + 1});
if (!disableESTransforms) {
rangesToRemove.push({start: tokens.currentIndex(), end: tokens.currentIndex() + 1});
}
tokens.nextToken();

@@ -85,2 +88,3 @@ } else if (tokens.currentToken().isType) {

let isESPrivate = false;
let isDeclare = false;
while (isAccessModifier(tokens.currentToken())) {

@@ -93,2 +97,5 @@ if (tokens.matches1(_types.TokenType._static)) {

}
if (tokens.matches1(_types.TokenType._declare)) {
isDeclare = true;
}
tokens.nextToken();

@@ -151,4 +158,8 @@ }

});
} else {
// This is just a declaration, so doesn't need to produce any code in the output.
} else if (!disableESTransforms || isDeclare) {
// This is a regular field declaration, like `x;`. With the class transform enabled, we just
// remove the line so that no output is produced. With the class transform disabled, we
// usually want to preserve the declaration (but still strip types), but if the `declare`
// keyword is specified, we should remove the line to avoid initializing the value to
// undefined.
rangesToRemove.push({start: statementStartIndex, end: tokens.currentIndex()});

@@ -160,11 +171,31 @@ }

tokens.restoreToSnapshot(snapshot);
return {
headerInfo,
constructorInitializerStatements,
instanceInitializerNames,
staticInitializerNames,
constructorInsertPos,
fields,
rangesToRemove,
};
if (disableESTransforms) {
// With ES transforms disabled, we don't want to transform regular class
// field declarations, and we don't need to do any additional tricks to
// reference the constructor for static init, but we still need to transform
// TypeScript field initializers defined as constructor parameters and we
// still need to remove `declare` fields. For now, we run the same code
// path but omit any field information, as if the class had no field
// declarations. In the future, when we fully drop the class fields
// transform, we can simplify this code significantly.
return {
headerInfo,
constructorInitializerStatements,
instanceInitializerNames: [],
staticInitializerNames: [],
constructorInsertPos,
fields: [],
rangesToRemove,
};
} else {
return {
headerInfo,
constructorInitializerStatements,
instanceInitializerNames,
staticInitializerNames,
constructorInsertPos,
fields,
rangesToRemove,
};
}
} exports.default = getClassInfo;

@@ -171,0 +202,0 @@

{
"name": "sucrase",
"version": "3.18.2",
"version": "3.19.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.0.5",
"sucrase": "^3.18.1",
"sucrase": "^3.18.2",
"test262-harness": "^6.5.0",

@@ -67,0 +67,0 @@ "ts-interface-builder": "^0.2.1",

@@ -71,3 +71,3 @@ # Sucrase

These proposed JS features are built-in and always transformed:
These newer JS features are transformed by default:
* [Optional chaining](https://github.com/tc39/proposal-optional-chaining): `a?.b`

@@ -77,4 +77,2 @@ * [Nullish coalescing](https://github.com/tc39/proposal-nullish-coalescing): `a ?? b`

This includes static fields but not the `#x` private field syntax.
* [Export namespace syntax](https://github.com/tc39/proposal-export-ns-from):
`export * as a from 'a';`
* [Numeric separators](https://github.com/tc39/proposal-numeric-separator):

@@ -85,2 +83,10 @@ `const n = 1_234;`

If your target runtime supports these features, you can specify
`disableESTransforms: true` so that Sucrase preserves the syntax rather than
trying to transform it. Note that transpiled and standard class fields behave
slightly differently; see the
[TypeScript 3.7 release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier)
for details. If you use TypeScript, you can enable the TypeScript option
`useDefineForClassFields` to enable error checking related to these differences.
### Unsupported syntax

@@ -87,0 +93,0 @@

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc