diff --git a/package.json b/package.json index 5798cfc..cc3404c 100644 --- a/package.json +++ b/package.json @@ -153,6 +153,7 @@ "@babel/runtime": "^7.12.5", "@babel/template": "^7.12.7", "@babel/types": "^7.12.12", + "babel-parse-wild-code": "^1.0.0", "chalk": "^4.1.0", "diff": "^5.0.0", "fs-extra": "^9.0.1", diff --git a/src/cli.ts b/src/cli.ts index d654d0a..596b2ab 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -12,7 +12,7 @@ import * as Path from 'path' import yargs from 'yargs' import prettier from 'prettier' import inquirer from 'inquirer' -import defaultParseFile from './util/defaultParseFile' +import { getParserAsync } from 'babel-parse-wild-code' import ansiEscapes from 'ansi-escapes' import { glob, hasMagic } from 'glob-gitignore' @@ -79,7 +79,10 @@ async function go(): Promise { } const context = new ConversionContext({ - parseFile: defaultParseFile, + parseFile: async (file: string) => + recast.parse(await fs.readFile(file, 'utf8'), { + parser: await getParserAsync(file, { tokens: true }), + }), defaultExact, resolve: (file: string, options: { basedir: string }): Promise => promisify(resolve as any)(file, { diff --git a/yarn.lock b/yarn.lock index eae6926..9cf2cdd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -266,6 +266,11 @@ resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.12.16.tgz#cc31257419d2c3189d394081635703f549fc1ed4" integrity sha512-c/+u9cqV6F0+4Hpq01jnJO+GLp2DdT63ppz9Xa+6cHaajM9VFzK/iDXiKK65YtpeVwu+ctfS6iqlMqRgQRzeCw== +"@babel/parser@^7.13.13": + version "7.13.13" + resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.13.13.tgz#42f03862f4aed50461e543270916b47dd501f0df" + integrity sha512-OhsyMrqygfk5v8HmWwOzlYjJrtLaFhF34MrfG/Z73DgYCI6ojNUTUp2TYbtnjo8PegeJp12eamsNettCQjKjVw== + "@babel/plugin-proposal-async-generator-functions@^7.12.13": version "7.12.13" resolved "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.12.13.tgz#d1c6d841802ffb88c64a2413e311f7345b9e66b5" @@ -888,6 +893,15 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" +"@babel/types@^7.13.14": + version "7.13.14" + resolved "https://registry.npmjs.org/@babel/types/-/types-7.13.14.tgz#c35a4abb15c7cd45a2746d78ab328e362cbace0d" + integrity sha512-A2aa3QTkWoyqsZZFl56MLUsfmh7O0gN41IPvXAE/++8ojpbz12SszD7JEGYVdn4f9Kt4amIei07swF1h4AqmmQ== + dependencies: + "@babel/helper-validator-identifier" "^7.12.11" + lodash "^4.17.19" + to-fast-properties "^2.0.0" + "@commitlint/cli@^11.0.0": version "11.0.0" resolved "https://registry.npmjs.org/@commitlint/cli/-/cli-11.0.0.tgz#698199bc52afed50aa28169237758fa14a67b5d3" @@ -1942,6 +1956,16 @@ babel-eslint@^10.1.0: eslint-visitor-keys "^1.0.0" resolve "^1.12.0" +babel-parse-wild-code@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/babel-parse-wild-code/-/babel-parse-wild-code-1.0.0.tgz#b2a6ab9a165dfcc0ba23957f6af8389d5c2addf4" + integrity sha512-96vIeky7P5fsV5kSE/hrDJosBwfpy/nP4OZ9dAtbVOIvgRDS/wPoA/NnnN8od/NMfV9I0K4F6Au6ys59PBMAZQ== + dependencies: + "@babel/parser" "^7.13.13" + "@babel/runtime" "^7.12.5" + "@babel/types" "^7.13.14" + resolve "^1.20.0" + babel-plugin-dynamic-import-node@^2.3.3: version "2.3.3" resolved "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3" @@ -7277,7 +7301,7 @@ resolve@1.1.x: resolved "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= -resolve@^1.10.0, resolve@^1.12.0, resolve@^1.17.0, resolve@^1.19.0: +resolve@^1.10.0, resolve@^1.12.0, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0: version "1.20.0" resolved "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==