diff --git a/package.json b/package.json index 4e31bbcaa..0a70dbc7c 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,10 @@ "dependencies": { "@babel/core": "^7.4.4", "@babel/helper-module-imports": "^7.0.0", + "@babel/parser": "^7.11.5", "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/preset-env": "^7.11.0", + "@babel/traverse": "^7.11.5", "@rollup/plugin-babel": "^5.1.0", "@rollup/plugin-commonjs": "^11.0.0", "@rollup/plugin-json": "^4.0.0", @@ -61,8 +63,6 @@ "babel-plugin-macros": "^2.6.1", "babel-plugin-polyfill-regenerator": "^0.0.4", "babel-plugin-transform-rename-import": "^2.3.0", - "babel-traverse": "^6.26.0", - "babylon": "^6.18.0", "camelcase": "^6.0.0", "chalk": "^4.0.0", "enquirer": "^2.3.4", diff --git a/src/env.d.ts b/src/env.d.ts index fe32705b6..9cd3924d8 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -12,8 +12,7 @@ declare module '@babel/core' { // Rollup plugins declare module 'rollup-plugin-terser'; -declare module 'babel-traverse'; -declare module 'babylon'; +declare module '@babel/traverse'; declare module '@babel/helper-module-imports'; declare module 'lodash.merge'; diff --git a/src/errors/evalToString.ts b/src/errors/evalToString.ts index da9e68192..fb819ae26 100644 --- a/src/errors/evalToString.ts +++ b/src/errors/evalToString.ts @@ -1,6 +1,15 @@ +// largely borrowed from https://github.com/facebook/react/blob/8b2d3783e58d1acea53428a10d2035a8399060fe/scripts/shared/evalToString.js +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + export function evalToString(ast: any): string { switch (ast.type) { case 'StringLiteral': + case 'Literal': // ESLint return ast.value; case 'BinaryExpression': // `+` if (ast.operator !== '+') { diff --git a/src/errors/extractErrors.ts b/src/errors/extractErrors.ts index 815cd18f0..9e6ca168e 100644 --- a/src/errors/extractErrors.ts +++ b/src/errors/extractErrors.ts @@ -1,3 +1,4 @@ +// largely borrowed from https://github.com/facebook/react/blob/8b2d3783e58d1acea53428a10d2035a8399060fe/scripts/error-codes/extract-errors.js /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -5,17 +6,17 @@ * LICENSE file in the root directory of this source tree. */ import fs from 'fs-extra'; -import * as babylon from 'babylon'; -import traverse from 'babel-traverse'; +import { parse, ParserOptions } from '@babel/parser'; +import traverse from '@babel/traverse'; import { invertObject } from './invertObject'; import { evalToString } from './evalToString'; import { paths } from '../constants'; import { safeVariableName } from '../utils'; import { pascalCase } from 'pascal-case'; -const babylonOptions = { +const babelParserOptions: ParserOptions = { sourceType: 'module', - // As a parser, babylon has its own options and we can't directly + // As a parser, @babel/parser has its own options and we can't directly // import/require a babel preset. It should be kept **the same** as // the `babel-plugin-syntax-*` ones specified in // https://github.com/facebook/fbjs/blob/master/packages/babel-preset-fbjs/configure.js @@ -26,7 +27,7 @@ const babylonOptions = { 'trailingFunctionCommas', 'objectRestSpread', ], -}; +} as ParserOptions; // workaround for trailingFunctionCommas syntax export async function extractErrors(opts: any) { if (!opts || !('errorMapFilePath' in opts)) { @@ -64,7 +65,7 @@ export async function extractErrors(opts: any) { existingErrorMap = invertObject(existingErrorMap); function transform(source: string) { - const ast = babylon.parse(source, babylonOptions); + const ast = parse(source, babelParserOptions); traverse(ast, { CallExpression: { @@ -111,7 +112,7 @@ function ErrorDev(message) { return error; } -export default ErrorDev; +export default ErrorDev; `, 'utf-8' ); diff --git a/src/errors/invertObject.ts b/src/errors/invertObject.ts index 23fd54f53..13959e9e9 100644 --- a/src/errors/invertObject.ts +++ b/src/errors/invertObject.ts @@ -1,3 +1,12 @@ +// largely borrowed from https://github.com/facebook/react/blob/8b2d3783e58d1acea53428a10d2035a8399060fe/scripts/error-codes/invertObject.js + +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + /** * turns * { 'MUCH ERROR': '0', 'SUCH WRONG': '1' } @@ -7,9 +16,7 @@ type Dict = { [key: string]: any }; -export function invertObject( - targetObj: Dict /* : ErrorMap */ -) /* : ErrorMap */ { +export function invertObject(targetObj: Dict) { const result: Dict = {}; const mapKeys = Object.keys(targetObj); diff --git a/src/errors/transformErrorMessages.ts b/src/errors/transformErrorMessages.ts index 08d144234..acea7088a 100644 --- a/src/errors/transformErrorMessages.ts +++ b/src/errors/transformErrorMessages.ts @@ -1,3 +1,11 @@ +// largely borrowed from https://github.com/facebook/react/blob/2c8832075b05009bd261df02171bf9888ac76350/scripts/error-codes/transform-error-messages.js +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + import fs from 'fs'; import { invertObject } from './invertObject'; import { evalToString } from './evalToString'; diff --git a/yarn.lock b/yarn.lock index 227cb54d1..1c1671c73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1808,15 +1808,6 @@ axobject-query@^2.0.2: "@babel/runtime" "^7.7.4" "@babel/runtime-corejs3" "^7.7.4" -babel-code-frame@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" - integrity sha1-Y/1D99weO7fONZR9uP42mj9Yx0s= - dependencies: - chalk "^1.1.3" - esutils "^2.0.2" - js-tokens "^3.0.2" - babel-eslint@^10.0.3: version "10.0.3" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a" @@ -1842,13 +1833,6 @@ babel-jest@^25.3.0: chalk "^3.0.0" slash "^3.0.0" -babel-messages@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" - integrity sha1-8830cDhYA1sqKVHG7F7fbGLyYw4= - dependencies: - babel-runtime "^6.22.0" - babel-plugin-annotate-pure-calls@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/babel-plugin-annotate-pure-calls/-/babel-plugin-annotate-pure-calls-0.4.0.tgz#78aa00fd878c4fcde4d49f3da397fcf5defbcce8" @@ -1949,44 +1933,6 @@ babel-preset-jest@^25.3.0: babel-plugin-jest-hoist "^25.2.6" babel-preset-current-node-syntax "^0.1.2" -babel-runtime@^6.22.0, babel-runtime@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" - integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4= - dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.11.0" - -babel-traverse@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" - integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4= - dependencies: - babel-code-frame "^6.26.0" - babel-messages "^6.23.0" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - debug "^2.6.8" - globals "^9.18.0" - invariant "^2.2.2" - lodash "^4.17.4" - -babel-types@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" - integrity sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc= - dependencies: - babel-runtime "^6.26.0" - esutils "^2.0.2" - lodash "^4.17.4" - to-fast-properties "^1.0.3" - -babylon@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" - integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ== - bail@^1.0.0: version "1.0.4" resolved "https://registry.yarnpkg.com/bail/-/bail-1.0.4.tgz#7181b66d508aa3055d3f6c13f0a0c720641dde9b" @@ -2559,11 +2505,6 @@ core-js-pure@^3.0.0: resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.4.7.tgz#c998e1892da9949200c7452cbd33c0df95be9f54" integrity sha512-Am3uRS8WCdTFA3lP7LtKR0PxgqYzjAMGKXaZKSNSC/8sqU0Wfq8R/YzoRs2rqtOVEunfgH+0q3O0BKOg0AvjPw== -core-js@^2.4.0: - version "2.6.10" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.10.tgz#8a5b8391f8cc7013da703411ce5b585706300d7f" - integrity sha512-I39t74+4t+zau64EN1fE5v2W31Adtc/REhzWN+gWRRXg6WH5qAsZm62DHpQ1+Yhe4047T55jvzz7MUqF/dBBlA== - core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -3818,11 +3759,6 @@ globals@^12.1.0: dependencies: type-fest "^0.8.1" -globals@^9.18.0: - version "9.18.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" - integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ== - globalyzer@^0.1.0: version "0.1.4" resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f" @@ -5056,11 +4992,6 @@ jpjs@^1.2.1: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-tokens@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" - integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= - js-yaml@^3.13.1: version "3.13.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" @@ -5402,7 +5333,7 @@ lodash.zip@^4.2.0: resolved "https://registry.yarnpkg.com/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020" integrity sha1-7GZi5IlkCO1KtsVCo5kLcswIACA= -lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4: +lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== @@ -6967,11 +6898,6 @@ regenerate@^1.4.0: resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== -regenerator-runtime@^0.11.0: - version "0.11.1" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" - integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== - regenerator-runtime@^0.13.2, regenerator-runtime@^0.13.4, regenerator-runtime@^0.13.7: version "0.13.7" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55" @@ -8033,11 +7959,6 @@ tmpl@1.0.x: resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" integrity sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE= -to-fast-properties@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" - integrity sha1-uDVx+k2MJbguIxsG46MFXeTKGkc= - to-fast-properties@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"