Skip to content

Commit

Permalink
fix(package): update dependencies and fix code
Browse files Browse the repository at this point in the history
TypeScript 2.7 is stricter than 2.6, so we have a few things to fix for that. On top of that, we have to pin recast to v0.13.0 (vs v0.13.1) since there's a regression with `NumericLiteral` nodes in v0.13.1 (benjamn/recast#469).
  • Loading branch information
eventualbuddha committed Feb 17, 2018
1 parent d3134b7 commit f076924
Showing 5 changed files with 541 additions and 471 deletions.
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -38,52 +38,52 @@
"author": "Brian Donovan <donovan@squareup.com>",
"license": "Apache-2.0",
"devDependencies": {
"@commitlint/cli": "^6.0.1",
"@commitlint/config-conventional": "^6.0.2",
"@commitlint/cli": "^6.1.0",
"@commitlint/config-conventional": "^6.1.0",
"@types/babel-traverse": "^6.7.16",
"@types/babylon": "^6.7.15",
"@types/get-port": "^3.2.0",
"@types/get-stream": "^3.0.1",
"@types/glob": "^5.0.30",
"@types/got": "^7.1.6",
"@types/glob": "^5.0.35",
"@types/got": "^7.1.7",
"@types/make-dir": "^1.0.3",
"@types/mocha": "^2.2.45",
"@types/mocha": "^2.2.48",
"@types/mz": "0.0.32",
"@types/node": "^9.3.0",
"@types/node": "^9.4.6",
"@types/rimraf": "2.0.2",
"@types/source-map-support": "^0.4.0",
"@types/tmp": "^0.0.33",
"commitlint": "^6.0.1",
"commitlint": "^6.1.0",
"get-port": "^3.2.0",
"globby": "^8.0.0",
"husky": "^0.14.3",
"lint-staged": "^6.0.0",
"lint-staged": "^6.1.1",
"make-dir": "^1.1.0",
"mocha": "^5.0.0",
"mocha": "^5.0.1",
"prettier": "1.10.2",
"prettier-check": "^2.0.0",
"rimraf": "2.6.2",
"semantic-release": "^11.0.2",
"tslint": "^5.4.2",
"tslint-config-prettier": "^1.6.0",
"typescript": "^2.2.1",
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.8.0",
"typescript": "^2.7.2",
"yarnhook": "^0.1.1"
},
"dependencies": {
"@babel/core": "^7.0.0-beta.38",
"@babel/generator": "^7.0.0-beta.38",
"@babel/preset-env": "^7.0.0-beta.38",
"@babel/preset-typescript": "^7.0.0-beta.38",
"@babel/traverse": "^7.0.0-beta.38",
"@babel/types": "^7.0.0-beta.38",
"@babel/core": "^7.0.0-beta.40",
"@babel/generator": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"@babel/preset-typescript": "^7.0.0-beta.40",
"@babel/traverse": "^7.0.0-beta.40",
"@babel/types": "^7.0.0-beta.40",
"get-stream": "^3.0.0",
"glob": "^7.1.2",
"got": "^8.0.1",
"got": "^8.1.0",
"mz": "^2.7.0",
"pirates": "^3.0.2",
"recast": "^0.13.0",
"recast": "0.13.0",
"resolve": "^1.5.0",
"source-map-support": "^0.5.0",
"source-map-support": "^0.5.3",
"tmp": "^0.0.33",
"whatwg-url": "^6.4.0"
},
51 changes: 26 additions & 25 deletions src/RecastPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as Babel from '@babel/core';
import { GeneratorOptions } from '@babel/generator';
import * as recast from 'recast';
import { AST, ParseOptions } from './TransformRunner';

const DEFAULT_OPTIONS = {
sourceType: 'module',
@@ -21,30 +23,29 @@ const DEFAULT_OPTIONS = {
]
};

type ParseOptions = object;
type AST = object;

export default {
parserOverride(
code: string,
options: ParseOptions,
parse: (code: string, options: ParseOptions) => AST
): AST {
return recast.parse(code, {
parser: {
parse(code: string) {
return parse(code, DEFAULT_OPTIONS);
export default function(babel: Babel) {
return {
parserOverride(
code: string,
options: ParseOptions,
parse: (code: string, options: ParseOptions) => AST
): AST {
return recast.parse(code, {
parser: {
parse(code: string) {
return parse(code, DEFAULT_OPTIONS);
}
}
}
});
},
});
},

generatorOverride(
ast: AST,
options: GeneratorOptions,
code: string,
generate: (ast: AST, options: GeneratorOptions) => string
): string {
return recast.print(ast);
}
};
generatorOverride(
ast: AST,
options: GeneratorOptions,
code: string,
generate: (ast: AST, options: GeneratorOptions) => string
): string {
return recast.print(ast);
}
};
}
20 changes: 19 additions & 1 deletion src/TransformRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Babel from '@babel/core';
import { transform } from '@babel/core';
import { GeneratorOptions } from '@babel/generator';
import { Visitor } from '@babel/traverse';

export class Source {
@@ -14,9 +15,26 @@ export class SourceTransformResult {
) {}
}

export type ParseOptions = object;
export type AST = object;

export type RawBabelPlugin = (
babel: typeof Babel
) => { name?: string; visitor: Visitor };
) => {
name?: string;
visitor?: Visitor;
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
) => string;
};
export type RawBabelPluginWithOptions = [RawBabelPlugin, object];
export type BabelPlugin = RawBabelPlugin | RawBabelPluginWithOptions;

2 changes: 1 addition & 1 deletion test/unit/OptionsTest.ts
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ describe('Options', function() {

it('interprets `--require` as expected', function() {
let options = assertOptionsParsed(Options.parse(['--require', 'mz']));
deepEqual(options.requires, ['mz'].map(require.resolve));
deepEqual(options.requires, ['mz'].map(name => require.resolve(name)));
});

it('associates plugin options based on inferred name', async function() {
Loading

0 comments on commit f076924

Please sign in to comment.