Comparing version 3.17.1 to 3.18.0
@@ -0,1 +1,7 @@ | ||
# 3.18.0 (2021-04-11) | ||
* Add `jest` transform analogous to `babel-plugin-jest-hoist`. ([#540]) (Patrik Oldsberg) | ||
* When calling a `register` function or `addHook`, return a function that | ||
reverts the hook. ([#604]) (Anthony Fu) | ||
# 3.17.1 (2021-01-31) | ||
@@ -329,1 +335,3 @@ | ||
[#593]: https://github.com/alangpierce/sucrase/pull/593 | ||
[#540]: https://github.com/alangpierce/sucrase/pull/540 | ||
[#604]: https://github.com/alangpierce/sucrase/pull/604 |
@@ -13,2 +13,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; } }/** | ||
t.lit("react-hot-loader"), | ||
t.lit("jest"), | ||
); exports.Transform = Transform; | ||
@@ -15,0 +16,0 @@ |
@@ -1,2 +0,2 @@ | ||
export declare type Transform = "jsx" | "typescript" | "flow" | "imports" | "react-hot-loader"; | ||
export declare type Transform = "jsx" | "typescript" | "flow" | "imports" | "react-hot-loader" | "jest"; | ||
export interface SourceMapOptions { | ||
@@ -3,0 +3,0 @@ /** |
@@ -6,9 +6,10 @@ import { Options } from "./index"; | ||
} | ||
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; | ||
export declare type RevertFunction = () => void; | ||
export declare function addHook(extension: string, options: Options, hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerJS(hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerJSX(hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerTS(hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerTSX(hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerTSLegacyModuleInterop(hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerTSXLegacyModuleInterop(hookOptions?: HookOptions): RevertFunction; | ||
export declare function registerAll(hookOptions?: HookOptions): RevertFunction; |
@@ -10,4 +10,10 @@ "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); | ||
function addHook(extension, options, hookOptions) { | ||
pirates.addHook( | ||
function addHook( | ||
extension, | ||
options, | ||
hookOptions, | ||
) { | ||
return pirates.addHook( | ||
(code, filePath) => { | ||
@@ -28,19 +34,19 @@ const {code: transformedCode, sourceMap} = _index.transform.call(void 0, code, { | ||
function registerJS(hookOptions) { | ||
addHook(".js", {transforms: ["imports", "flow", "jsx"]}, hookOptions); | ||
return addHook(".js", {transforms: ["imports", "flow", "jsx"]}, hookOptions); | ||
} exports.registerJS = registerJS; | ||
function registerJSX(hookOptions) { | ||
addHook(".jsx", {transforms: ["imports", "flow", "jsx"]}, hookOptions); | ||
return addHook(".jsx", {transforms: ["imports", "flow", "jsx"]}, hookOptions); | ||
} exports.registerJSX = registerJSX; | ||
function registerTS(hookOptions) { | ||
addHook(".ts", {transforms: ["imports", "typescript"]}, hookOptions); | ||
return addHook(".ts", {transforms: ["imports", "typescript"]}, hookOptions); | ||
} exports.registerTS = registerTS; | ||
function registerTSX(hookOptions) { | ||
addHook(".tsx", {transforms: ["imports", "typescript", "jsx"]}, hookOptions); | ||
return addHook(".tsx", {transforms: ["imports", "typescript", "jsx"]}, hookOptions); | ||
} exports.registerTSX = registerTSX; | ||
function registerTSLegacyModuleInterop(hookOptions) { | ||
addHook( | ||
return addHook( | ||
".ts", | ||
@@ -56,3 +62,3 @@ { | ||
function registerTSXLegacyModuleInterop(hookOptions) { | ||
addHook( | ||
return addHook( | ||
".tsx", | ||
@@ -68,6 +74,14 @@ { | ||
function registerAll(hookOptions) { | ||
registerJS(hookOptions); | ||
registerJSX(hookOptions); | ||
registerTS(hookOptions); | ||
registerTSX(hookOptions); | ||
const reverts = [ | ||
registerJS(hookOptions), | ||
registerJSX(hookOptions), | ||
registerTS(hookOptions), | ||
registerTSX(hookOptions), | ||
]; | ||
return () => { | ||
for (const fn of reverts) { | ||
fn(); | ||
} | ||
}; | ||
} exports.registerAll = registerAll; |
@@ -171,7 +171,9 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
removeInitialToken() { | ||
this.replaceToken(""); | ||
this.resultCode += this.previousWhitespaceAndComments(); | ||
this.tokenIndex++; | ||
} | ||
removeToken() { | ||
this.replaceTokenTrimmingLeftWhitespace(""); | ||
this.resultCode += this.previousWhitespaceAndComments().replace(/[^\r\n]/g, ""); | ||
this.tokenIndex++; | ||
} | ||
@@ -178,0 +180,0 @@ |
@@ -11,2 +11,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _FlowTransformer = require('./FlowTransformer'); var _FlowTransformer2 = _interopRequireDefault(_FlowTransformer); | ||
var _JestHoistTransformer = require('./JestHoistTransformer'); var _JestHoistTransformer2 = _interopRequireDefault(_JestHoistTransformer); | ||
var _JSXTransformer = require('./JSXTransformer'); var _JSXTransformer2 = _interopRequireDefault(_JSXTransformer); | ||
@@ -104,2 +105,7 @@ var _NumericSeparatorTransformer = require('./NumericSeparatorTransformer'); var _NumericSeparatorTransformer2 = _interopRequireDefault(_NumericSeparatorTransformer); | ||
} | ||
if (transforms.includes("jest")) { | ||
this.transformers.push( | ||
new (0, _JestHoistTransformer2.default)(this, tokenProcessor, this.nameManager, importProcessor), | ||
); | ||
} | ||
} | ||
@@ -118,2 +124,5 @@ | ||
prefix += this.generatedVariables.map((v) => ` var ${v};`).join(""); | ||
for (const transformer of this.transformers) { | ||
prefix += transformer.getHoistedCode(); | ||
} | ||
let suffix = ""; | ||
@@ -120,0 +129,0 @@ for (const transformer of this.transformers) { |
export default abstract class Transformer { | ||
abstract process(): boolean; | ||
getPrefixCode(): string; | ||
getHoistedCode(): string; | ||
getSuffixCode(): string; | ||
} |
@@ -9,2 +9,6 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); class Transformer { | ||
getHoistedCode() { | ||
return ""; | ||
} | ||
getSuffixCode() { | ||
@@ -11,0 +15,0 @@ return ""; |
{ | ||
"name": "sucrase", | ||
"version": "3.17.1", | ||
"version": "3.18.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.17.0", | ||
"sucrase": "^3.17.1", | ||
"test262-harness": "^6.5.0", | ||
@@ -67,0 +67,0 @@ "ts-interface-builder": "^0.2.1", |
@@ -67,2 +67,5 @@ # Sucrase | ||
bound methods. | ||
* **jest**: Hoist desired [jest](https://jestjs.io/) method calls above imports in | ||
the same way as [babel-plugin-jest-hoist](https://github.com/facebook/jest/tree/master/packages/babel-plugin-jest-hoist). | ||
Does not validate the arguments passed to `jest.mock`, but the same rules still apply. | ||
@@ -69,0 +72,0 @@ These proposed JS features are built-in and always transformed: |
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
965437
181
24457
240