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

babel-codemod

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-codemod - npm Package Compare versions

Comparing version 2.0.8 to 2.1.0

27

package.json
{
"name": "babel-codemod",
"version": "2.0.8",
"version": "2.1.0",
"description": "babel-codemod rewrites JavaScript using babel plugins.",

@@ -35,6 +35,7 @@ "main": "src/index.js",

"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"@types/babel-traverse": "^6.25.3",
"@types/babylon": "^6.16.2",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@types/babel__core": "^7.0.2",
"@types/babel__generator": "^7.0.1",
"@types/babel__traverse": "^7.0.1",
"@types/get-port": "^4.0.0",

@@ -47,4 +48,4 @@ "@types/get-stream": "^3.0.1",

"@types/mz": "0.0.32",
"@types/node": "^10.3.0",
"@types/prettier": "^1.12.4",
"@types/node": "^10.12.9",
"@types/prettier": "^1.15.1",
"@types/rimraf": "2.0.2",

@@ -54,5 +55,5 @@ "@types/semver": "^5.5.0",

"@types/tmp": "^0.0.33",
"commitlint": "^7.0.0",
"commitlint": "^7.2.1",
"get-port": "^4.0.0",
"husky": "^1.0.0",
"husky": "^1.1.4",
"lint-staged": "^8.0.5",

@@ -63,6 +64,6 @@ "make-dir": "^1.3.0",

"rimraf": "2.6.2",
"semver": "^5.5.0",
"tslint": "^5.10.0",
"tslint-config-prettier": "^1.13.0",
"typescript": "^2.9.1",
"semver": "^5.6.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.1.6",
"yarnhook": "^0.3.0"

@@ -69,0 +70,0 @@ },

import * as Babel from '@babel/core';
import { BabelOptions, ParseOptions } from './BabelPluginTypes';
export default function (babel: typeof Babel): {
manipulateOptions(opts: BabelOptions, parserOpts: ParseOptions): void;
};
import { BabelPlugin } from './BabelPluginTypes';
export default function buildPlugin(sourceType: Babel.ParserOptions['sourceType']): BabelPlugin;

@@ -10,3 +10,2 @@ "use strict";

'doExpressions',
'exportExtensions',
'functionBind',

@@ -24,17 +23,20 @@ 'functionSent',

}
function default_1(babel) {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.sourceType = 'module';
parserOpts.allowImportExportEverywhere = true;
parserOpts.allowReturnOutsideFunction = true;
parserOpts.allowSuperOutsideMethod = true;
parserOpts.plugins = [
...(parserOpts.plugins || []),
...pluginsForFilename(opts.filename)
];
}
function buildPlugin(sourceType) {
return function (babel) {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.sourceType = sourceType;
parserOpts.allowImportExportEverywhere = true;
parserOpts.allowReturnOutsideFunction = true;
parserOpts.allowSuperOutsideMethod = true;
// Cast this because @babel/types typings don't allow plugin options.
parserOpts.plugins = [
...(parserOpts.plugins || []),
...pluginsForFilename(opts.filename)
];
}
};
};
}
exports.default = default_1;
exports.default = buildPlugin;
//# sourceMappingURL=AllSyntaxPlugin.js.map
import * as Babel from '@babel/core';
import { GeneratorOptions } from '@babel/generator';
import { Visitor } from '@babel/traverse';
export interface BabelOptions {
filename: string;
}
export interface ParseOptions {
sourceType?: 'module' | 'script';
allowImportExportEverywhere?: boolean;
allowReturnOutsideFunction?: boolean;
allowSuperOutsideMethod?: boolean;
plugins?: Array<string | [string, object]>;
tokens?: boolean;
}
export declare type AST = object;
export declare type RawBabelPlugin = (babel: typeof Babel) => {
name?: string;
visitor?: Visitor;
manipulateOptions?: (opts: object, parserOpts: ParseOptions) => void;
parserOverride?: (code: string, options: ParseOptions, parse: (code: string, options: ParseOptions) => AST) => AST;
generatorOverride?: (ast: AST, options: GeneratorOptions, code: string, generate: (ast: AST, options: GeneratorOptions) => string) => {
import { File } from '@babel/types';
/**
* Fixes the `PluginObj` type from `@babel/core` by making all fields optional
* and adding parser and generator override methods.
*/
export interface PluginObj<S = File> extends Partial<Babel.PluginObj<S>> {
parserOverride?(code: string, options: Babel.ParserOptions, parse: (code: string, options: Babel.ParserOptions) => File): File;
generatorOverride?(ast: File, options: Babel.GeneratorOptions, code: string, generate: (ast: File, options: Babel.GeneratorOptions) => string): {
code: string;
map?: object;
};
};
}
export declare type RawBabelPlugin = (babel: typeof Babel) => PluginObj;
export declare type RawBabelPluginWithOptions = [RawBabelPlugin, object];
export declare type BabelPlugin = RawBabelPlugin | RawBabelPluginWithOptions;

@@ -81,3 +81,3 @@ "use strict";

for (var _b = __asyncValues(runner.run()), _c; _c = yield _b.next(), !_c.done;) {
let result = yield _c.value;
let result = _c.value;
this.onTransform(result);

@@ -84,0 +84,0 @@ if (result.kind === TransformRunner_1.SourceTransformResultKind.Transformed) {

@@ -0,1 +1,2 @@

import { ParserOptions } from '@babel/parser';
import { BabelPlugin, RawBabelPlugin } from './BabelPluginTypes';

@@ -23,2 +24,3 @@ import { PathPredicate } from './iterateSources';

readonly extensions: Set<string>;
readonly sourceType: ParserOptions['sourceType'];
readonly requires: Array<string>;

@@ -30,3 +32,3 @@ readonly transpilePlugins: boolean;

readonly dry: boolean;
constructor(sourcePaths?: Array<string>, localPlugins?: Array<string>, remotePlugins?: Array<string>, pluginOptions?: Map<string, object>, printer?: Printer, extensions?: Set<string>, requires?: Array<string>, transpilePlugins?: boolean, findBabelConfig?: boolean, ignore?: PathPredicate, stdio?: boolean, dry?: boolean);
constructor(sourcePaths?: Array<string>, localPlugins?: Array<string>, remotePlugins?: Array<string>, pluginOptions?: Map<string, object>, printer?: Printer, extensions?: Set<string>, sourceType?: ParserOptions['sourceType'], requires?: Array<string>, transpilePlugins?: boolean, findBabelConfig?: boolean, ignore?: PathPredicate, stdio?: boolean, dry?: boolean);
private pluginLoader;

@@ -50,2 +52,3 @@ private remotePluginLoader;

private _extensions;
private _sourceType;
private _requires?;

@@ -69,2 +72,3 @@ private _transpilePlugins?;

addExtension(value: string): this;
sourceType(value: ParserOptions['sourceType']): this;
requires(value: Array<string>): this;

@@ -71,0 +75,0 @@ addRequire(value: string): this;

@@ -48,3 +48,3 @@ "use strict";

class Config {
constructor(sourcePaths = [], localPlugins = [], remotePlugins = [], pluginOptions = new Map(), printer = Printer.Recast, extensions = extensions_1.TransformableExtensions, requires = [], transpilePlugins = true, findBabelConfig = false, ignore = ignoreDotfiles, stdio = false, dry = false) {
constructor(sourcePaths = [], localPlugins = [], remotePlugins = [], pluginOptions = new Map(), printer = Printer.Recast, extensions = extensions_1.TransformableExtensions, sourceType = 'unambiguous', requires = [], transpilePlugins = true, findBabelConfig = false, ignore = ignoreDotfiles, stdio = false, dry = false) {
this.sourcePaths = sourcePaths;

@@ -56,2 +56,3 @@ this.localPlugins = localPlugins;

this.extensions = extensions;
this.sourceType = sourceType;
this.requires = requires;

@@ -118,3 +119,3 @@ this.transpilePlugins = transpilePlugins;

return __awaiter(this, void 0, void 0, function* () {
let result = [AllSyntaxPlugin_1.default];
let result = [AllSyntaxPlugin_1.default(this.sourceType)];
switch (this.printer) {

@@ -164,2 +165,3 @@ case Printer.Recast:

this._extensions = new Set(extensions_1.TransformableExtensions);
this._sourceType = 'module';
}

@@ -231,2 +233,6 @@ sourcePaths(value) {

}
sourceType(value) {
this._sourceType = value;
return this;
}
requires(value) {

@@ -264,3 +270,3 @@ this._requires = value;

build() {
return new Config(this._sourcePaths, this._localPlugins, this._remotePlugins, this._pluginOptions, this._printer, this._extensions, this._requires, this._transpilePlugins, this._findBabelConfig, this._ignore, this._stdio, this._dry);
return new Config(this._sourcePaths, this._localPlugins, this._remotePlugins, this._pluginOptions, this._printer, this._extensions, this._sourceType, this._requires, this._transpilePlugins, this._findBabelConfig, this._ignore, this._stdio, this._dry);
}

@@ -267,0 +273,0 @@ }

@@ -50,2 +50,4 @@ "use strict";

--extensions EXTS Comma-separated extensions to process (default: "${Array.from(defaults.extensions).join(',')}").
--source-type Parse as "module", "script", or "unambiguous" (meaning babel
will try to guess, default: "${defaults.sourceType}").
--[no-]transpile-plugins Transpile plugins to enable future syntax${optionAnnotation(defaults.transpilePlugins)}.

@@ -52,0 +54,0 @@ --[no-]find-babel-config Run plugins through babel plugins/presets specified in local

@@ -18,7 +18,11 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
return core_1.transform(content, {
let result = yield core_1.transformAsync(content, {
filename: filepath,
babelrc: false,
plugins: this.plugins
}).code;
});
if (!result) {
throw new Error(`[${filepath}] babel transform returned null`);
}
return result.code;
});

@@ -25,0 +29,0 @@ }

@@ -85,2 +85,16 @@ "use strict";

break;
case '--source-type': {
i++;
let sourceType = this.args[i];
if (sourceType === 'module' ||
sourceType === 'script' ||
sourceType === 'unambiguous') {
config.sourceType(sourceType);
}
else {
throw new Error(`expected '--source-type' to be one of "module", "script", ` +
`or "unambiguous" but got: "${sourceType}"`);
}
break;
}
case '-s':

@@ -87,0 +101,0 @@ case '--stdio':

import * as Babel from '@babel/core';
import { File } from '@babel/types';
import { parse } from './RecastPlugin';
export default function (babel: typeof Babel): {
parserOverride: typeof parse;
generatorOverride(ast: object, options: any, code: string, _generate: (ast: object, options: any) => string): {
generatorOverride(ast: File, options: Babel.GeneratorOptions, code: string, _generate: (ast: File, options: Babel.GeneratorOptions) => string): {
code: string;

@@ -7,0 +8,0 @@ map?: object | undefined;

import * as Babel from '@babel/core';
import { GeneratorOptions } from '@babel/generator';
import { AST, ParseOptions } from './BabelPluginTypes';
export declare function parse(code: string, options: ParseOptions, parse: (code: string, options: ParseOptions) => AST): AST;
export declare function generate(ast: AST, options: GeneratorOptions, code: string, generate: (ast: AST, options: GeneratorOptions) => string): {
import { File } from '@babel/types';
import { PluginObj } from './BabelPluginTypes';
export declare function parse(code: string, options: Babel.ParserOptions, parse: (code: string, options: Babel.ParserOptions) => File): File;
export declare function generate(ast: File, options: Babel.GeneratorOptions, code: string, generate: (ast: File, options: Babel.GeneratorOptions) => string): {
code: string;
map?: object;
};
export default function (babel: typeof Babel): {
parserOverride: typeof parse;
generatorOverride: typeof generate;
};
export default function (babel: typeof Babel): PluginObj;

@@ -15,7 +15,8 @@ "use strict";

}
let presets = [];
let options = {
filename,
babelrc: useBabelrc,
presets: [],
plugins: [AllSyntaxPlugin_1.default],
presets: presets,
plugins: [AllSyntaxPlugin_1.default('module')],
sourceMaps: 'inline'

@@ -25,7 +26,11 @@ };

if (extensions_1.TypeScriptExtensions.has(ext)) {
options.presets.push(require.resolve('@babel/preset-typescript'));
presets.push(require.resolve('@babel/preset-typescript'));
}
options.presets.push(require.resolve('@babel/preset-env'));
presets.push(require.resolve('@babel/preset-env'));
}
return core_1.transform(code, options).code;
let result = core_1.transformSync(code, options);
if (!result) {
throw new Error(`[${filename}] babel transform returned null`);
}
return result.code;
}

@@ -32,0 +37,0 @@ exports.hook = hook;

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

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

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