diff --git a/.eslintignore b/.eslintignore index 1fba0618658f..f9ba6f454a91 100644 --- a/.eslintignore +++ b/.eslintignore @@ -9,6 +9,7 @@ packages/babel-runtime-corejs2 packages/babel-runtime-corejs3 packages/*/node_modules packages/*/lib +packages/*/dts packages/*/dist packages/*/test/fixtures packages/*/test/tmp diff --git a/.eslintrc.js b/.eslintrc.js index c5664b53628b..188f06fde534 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,11 +19,24 @@ module.exports = { node: true, }, overrides: [ + { + files: ["**/*.ts"], + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint"], + rules: { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "error", + "no-dupe-class-members": "off", + "@typescript-eslint/no-dupe-class-members": "error", + "no-undef": "off", + "no-redeclare": "off", + }, + }, { files: [ - "packages/*/src/**/*.js", - "codemods/*/src/**/*.js", - "eslint/*/src/**/*.js", + "packages/*/src/**/*.{js,ts}", + "codemods/*/src/**/*.{js,ts}", + "eslint/*/src/**/*.{js,ts}", ], rules: { "@babel/development/no-undefined-identifier": "error", @@ -37,7 +50,7 @@ module.exports = { "packages/*/test/**/*.js", "codemods/*/test/**/*.js", "eslint/*/test/**/*.js", - "packages/babel-helper-transform-fixture-test-runner/src/helpers.js", + "packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}", "test/**/*.js", ], env: { @@ -53,7 +66,7 @@ module.exports = { }, }, { - files: ["packages/babel-plugin-*/src/index.js"], + files: ["packages/babel-plugin-*/src/index.{js,ts}"], excludedFiles: ["packages/babel-plugin-transform-regenerator/**/*.js"], rules: { "@babel/development/plugin-name": "error", @@ -61,7 +74,7 @@ module.exports = { }, }, { - files: ["packages/babel-parser/src/**/*.js"], + files: ["packages/babel-parser/src/**/*.{js,ts}"], rules: { "@babel/development-internal/dry-error-messages": [ "error", diff --git a/.flowconfig b/.flowconfig index 9dd89e023d55..11ea40a036c0 100644 --- a/.flowconfig +++ b/.flowconfig @@ -16,6 +16,7 @@ lib/parser.js lib/third-party-libs.js.flow lib/preset-modules.js.flow packages/babel-types/lib/index.js.flow +lib/babel-packages.js.flow [options] include_warnings=true diff --git a/.gitignore b/.gitignore index 6282dfa36ce0..d0b165651114 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,10 @@ packages/babel-standalone/babel.min.js /eslint/*/LICENSE !/packages/babel-eslint-plugin/LICENSE /.vscode + +/tsconfig.json +/packages/*/tsconfig.json +/packages/*/tsconfig.tsbuildinfo +/packages/*/dts +/codemods/*/dts +/eslint/*/dts diff --git a/.prettierrc b/.prettierrc index bfe4721c3432..978392877bc1 100644 --- a/.prettierrc +++ b/.prettierrc @@ -10,15 +10,14 @@ "printWidth": 80, "overrides": [{ "files": [ - "**/codemods/*/src/**/*.js", + "**/codemods/*/src/**/*.{js,ts}", "**/codemods/*/test/**/*.js", - "**/packages/*/src/**/*.js", + "**/packages/*/src/**/*.{js,ts}", "**/packages/*/test/**/*.js", - "**/eslint/*/src/**/*.js", + "**/eslint/*/src/**/*.{js,ts}", "**/eslint/*/test/**/*.js" ], "options": { - "parser": "babel", "trailingComma": "all" } }] diff --git a/Gulpfile.js b/Gulpfile.js index 0011b0fcbff2..be30c73e94dd 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -9,6 +9,7 @@ const fancyLog = require("fancy-log"); const filter = require("gulp-filter"); const gulp = require("gulp"); const path = require("path"); +const fs = require("fs"); const rollup = require("rollup"); const rollupBabel = require("@rollup/plugin-babel").default; const rollupBabelSource = require("./scripts/rollup-plugin-babel-source"); @@ -19,7 +20,7 @@ const rollupNodeResolve = require("@rollup/plugin-node-resolve").default; const rollupReplace = require("@rollup/plugin-replace"); const { terser: rollupTerser } = require("rollup-plugin-terser"); -const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.js"; +const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.{js,ts}"; function swapSrcWithLib(srcPath) { const parts = srcPath.split(path.sep); @@ -28,7 +29,12 @@ function swapSrcWithLib(srcPath) { } function getIndexFromPackage(name) { - return `${name}/src/index.js`; + try { + fs.statSync(`./${name}/src/index.ts`); + return `${name}/src/index.ts`; + } catch { + return `${name}/src/index.js`; + } } function compilationLogger() { @@ -121,8 +127,10 @@ function buildRollup(packages) { babelrc: false, babelHelpers: "bundled", extends: "./babel.config.js", + extensions: [".mjs", ".cjs", ".ts", ".js"], }), rollupNodeResolve({ + extensions: [".mjs", ".cjs", ".ts", ".js", ".json"], browser: nodeResolveBrowser, preferBuiltins: true, //todo: remove when semver and source-map are bumped to latest versions @@ -142,7 +150,7 @@ function buildRollup(packages) { rollupJson(), rollupNodePolyfills({ sourceMap: sourcemap, - include: "**/*.js", + include: "**/*.{js,ts}", }), ], }); diff --git a/Makefile b/Makefile index a291d780cc91..c4d51f3aa221 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,9 @@ build-bundle: clean clean-lib build-bundle-ci: bootstrap-only $(MAKE) build-bundle +generate-tsconfig: + $(NODE) scripts/generators/tsconfig.js + generate-standalone: $(NODE) packages/babel-standalone/scripts/generate.js @@ -49,6 +52,7 @@ build-flow-typings: build-typescript-typings: $(NODE) packages/babel-types/scripts/generators/typescript.js > packages/babel-types/lib/index.d.ts + $(NODE) packages/babel-types/scripts/generators/typescript.js --ts3.7 > packages/babel-types/lib/index-ts3.7.d.ts build-standalone: build-babel-standalone @@ -85,12 +89,16 @@ watch: build-no-bundle BABEL_ENV=development $(YARN) gulp watch code-quality-ci: build-no-bundle-ci - $(MAKE) flowcheck-ci lint-ci + $(MAKE) tscheck flowcheck-ci lint-ci flowcheck-ci: $(MAKE) flow -code-quality: flow lint +code-quality: tscheck flow lint + +tscheck: generate-tsconfig + make build-typescript-typings + $(YARN) tsc -b . flow: $(YARN) flow check --strip-root @@ -109,7 +117,7 @@ check-compat-data-ci: lint: lint-js lint-ts lint-js: - BABEL_ENV=test $(YARN) eslint scripts $(SOURCES) '*.js' --format=codeframe + BABEL_ENV=test $(YARN) eslint scripts $(SOURCES) '*.{js,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts lint-ts: scripts/lint-ts-typings.sh @@ -117,7 +125,7 @@ lint-ts: fix: fix-json fix-js fix-js: - $(YARN) eslint scripts $(SOURCES) '*.js' --format=codeframe --fix + $(YARN) eslint scripts $(SOURCES) '*.{js,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts --fix fix-json: $(YARN) prettier "{$(COMMA_SEPARATED_SOURCES)}/*/test/fixtures/**/options.json" --write --loglevel warn @@ -136,6 +144,10 @@ clean: test-clean rm -rf packages/*/npm-debug* rm -rf node_modules/.cache +clean-tsconfig: + rm -f tsconfig.json + rm -f packages/*/tsconfig.json + test-clean: $(foreach source, $(SOURCES), \ $(call clean-source-test, $(source))) @@ -211,6 +223,8 @@ clone-license: prepublish-build: clean-lib clean-runtime-helpers NODE_ENV=production BABEL_ENV=production $(MAKE) build-bundle $(MAKE) prepublish-build-standalone clone-license + # We don't want to publish .d.ts files yet + rm -rf packages/*/dts prepublish: $(MAKE) check-yarn-bug-1882 @@ -271,7 +285,7 @@ clean-runtime-helpers: rm -f packages/babel-runtime-corejs3/helpers/**/*.js rm -rf packages/babel-runtime-corejs2/core-js -clean-all: +clean-all: clean-tsconfig rm -rf node_modules rm -rf package-lock.json rm -rf .changelog diff --git a/babel.config.js b/babel.config.js index 24dfc34ff256..1716227855de 100644 --- a/babel.config.js +++ b/babel.config.js @@ -103,6 +103,10 @@ module.exports = function (api) { .filter(Boolean) .map(normalize), presets: [ + [ + "@babel/preset-typescript", + { onlyRemoveTypeImports: true, allowDeclareFields: true }, + ], ["@babel/env", envOpts], ["@babel/preset-flow", { allowDeclareFields: true }], ], diff --git a/lib/babel-packages.js.flow b/lib/babel-packages.js.flow new file mode 100644 index 000000000000..2f2c9a61bcfe --- /dev/null +++ b/lib/babel-packages.js.flow @@ -0,0 +1,36 @@ +declare module "@babel/template" { + declare type PublicOpts = { + placeholderWhitelist?: ?Set, + placeholderPattern?: ?(RegExp | false), + preserveComments?: ?boolean, + syntacticPlaceholders?: ?boolean, + }; + + declare type PublicReplacements = { [string]: mixed } | Array; + + declare type TemplateBuilder = { + ast: { + (tpl: string, opts: ?PublicOpts): T, + (tpl: Array, ...args: Array): T, + }, + (opts: PublicOpts): TemplateBuilder, + (tpl: string, opts: ?PublicOpts): (?PublicReplacements) => T, + (tpl: Array, ...args: Array): (?PublicReplacements) => T, + }; + + declare type Smart = TemplateBuilder< + Array | BabelNodeStatement + >; + declare type Statement = TemplateBuilder; + declare type Statements = TemplateBuilder>; + declare type Expression = TemplateBuilder; + declare type Program = TemplateBuilder; + + declare export default Smart & { + smart: Smart, + statement: Statement, + statements: Statements, + expression: Expression, + program: Program, + }; +} diff --git a/package.json b/package.json index 55109df577eb..a739c498704f 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@babel/plugin-transform-runtime": "^7.12.0", "@babel/preset-env": "^7.12.0", "@babel/preset-flow": "^7.10.4", + "@babel/preset-typescript": "^7.12.1", "@babel/register": "^7.12.0", "@babel/runtime": "^7.12.0", "@rollup/plugin-babel": "^5.2.0", @@ -34,6 +35,8 @@ "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^9.0.0", "@rollup/plugin-replace": "^2.3.3", + "@typescript-eslint/eslint-plugin": "^4.6.1", + "@typescript-eslint/parser": "^4.6.1", "babel-plugin-transform-charcodes": "^0.2.0", "chalk": "^2.4.2", "charcodes": "^0.2.0", @@ -61,7 +64,7 @@ "rollup-plugin-terser": "^7.0.0", "test262-stream": "^1.3.0", "through2": "^2.0.0", - "typescript": "^3.6.3" + "typescript": "^4.0.5" }, "workspaces": [ "codemods/*", @@ -78,7 +81,7 @@ "yarn": ">=1.4.0" }, "lint-staged": { - "*.js": [ + "*.{js,ts}": [ "eslint --format=codeframe" ] }, diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index 7a9d0ebab10e..044c81641f9c 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -8,144 +8,150 @@ /** * Parse the provided code as an entire ECMAScript program. */ -export function parse(input: string, options?: ParserOptions): import('@babel/types').File; +export function parse( + input: string, + options?: ParserOptions +): import("@babel/types").File; /** * Parse the provided code as a single expression. */ -export function parseExpression(input: string, options?: ParserOptions): import('@babel/types').Expression; +export function parseExpression( + input: string, + options?: ParserOptions +): import("@babel/types").Expression; export interface ParserOptions { - /** - * By default, import and export declarations can only appear at a program's top level. - * Setting this option to true allows them anywhere where a statement is allowed. - */ - allowImportExportEverywhere?: boolean; - - /** - * By default, await use is not allowed outside of an async function. - * Set this to true to accept such code. - */ - allowAwaitOutsideFunction?: boolean; - - /** - * By default, a return statement at the top level raises an error. - * Set this to true to accept such code. - */ - allowReturnOutsideFunction?: boolean; - - allowSuperOutsideMethod?: boolean; - - /** - * By default, exported identifiers must refer to a declared variable. - * Set this to true to allow export statements to reference undeclared variables. - */ - allowUndeclaredExports?: boolean; - - /** - * Indicate the mode the code should be parsed in. - * Can be one of "script", "module", or "unambiguous". Defaults to "script". - * "unambiguous" will make @babel/parser attempt to guess, based on the presence - * of ES6 import or export statements. - * Files with ES6 imports and exports are considered "module" and are otherwise "script". - */ - sourceType?: 'script' | 'module' | 'unambiguous'; - - /** - * Correlate output AST nodes with their source filename. - * Useful when generating code and source maps from the ASTs of multiple input files. - */ - sourceFilename?: string; - - /** - * By default, the first line of code parsed is treated as line 1. - * You can provide a line number to alternatively start with. - * Useful for integration with other source tools. - */ - startLine?: number; - - /** - * Array containing the plugins that you want to enable. - */ - plugins?: ParserPlugin[]; - - /** - * Should the parser work in strict mode. - * Defaults to true if sourceType === 'module'. Otherwise, false. - */ - strictMode?: boolean; - - /** - * Adds a ranges property to each node: [node.start, node.end] - */ - ranges?: boolean; - - /** - * Adds all parsed tokens to a tokens property on the File node. - */ - tokens?: boolean; - - /** - * By default, the parser adds information about parentheses by setting - * `extra.parenthesized` to `true` as needed. - * When this option is `true` the parser creates `ParenthesizedExpression` - * AST nodes instead of using the `extra` property. - */ - createParenthesizedExpressions?: boolean; + /** + * By default, import and export declarations can only appear at a program's top level. + * Setting this option to true allows them anywhere where a statement is allowed. + */ + allowImportExportEverywhere?: boolean; + + /** + * By default, await use is not allowed outside of an async function. + * Set this to true to accept such code. + */ + allowAwaitOutsideFunction?: boolean; + + /** + * By default, a return statement at the top level raises an error. + * Set this to true to accept such code. + */ + allowReturnOutsideFunction?: boolean; + + allowSuperOutsideMethod?: boolean; + + /** + * By default, exported identifiers must refer to a declared variable. + * Set this to true to allow export statements to reference undeclared variables. + */ + allowUndeclaredExports?: boolean; + + /** + * Indicate the mode the code should be parsed in. + * Can be one of "script", "module", or "unambiguous". Defaults to "script". + * "unambiguous" will make @babel/parser attempt to guess, based on the presence + * of ES6 import or export statements. + * Files with ES6 imports and exports are considered "module" and are otherwise "script". + */ + sourceType?: "script" | "module" | "unambiguous"; + + /** + * Correlate output AST nodes with their source filename. + * Useful when generating code and source maps from the ASTs of multiple input files. + */ + sourceFilename?: string; + + /** + * By default, the first line of code parsed is treated as line 1. + * You can provide a line number to alternatively start with. + * Useful for integration with other source tools. + */ + startLine?: number; + + /** + * Array containing the plugins that you want to enable. + */ + plugins?: ParserPlugin[]; + + /** + * Should the parser work in strict mode. + * Defaults to true if sourceType === 'module'. Otherwise, false. + */ + strictMode?: boolean; + + /** + * Adds a ranges property to each node: [node.start, node.end] + */ + ranges?: boolean; + + /** + * Adds all parsed tokens to a tokens property on the File node. + */ + tokens?: boolean; + + /** + * By default, the parser adds information about parentheses by setting + * `extra.parenthesized` to `true` as needed. + * When this option is `true` the parser creates `ParenthesizedExpression` + * AST nodes instead of using the `extra` property. + */ + createParenthesizedExpressions?: boolean; } export type ParserPlugin = - 'asyncGenerators' | - 'bigInt' | - 'classPrivateMethods' | - 'classPrivateProperties' | - 'classProperties' | - 'classStaticBlock' | - 'decimal' | - 'decorators' | - 'decorators-legacy' | - 'doExpressions' | - 'dynamicImport' | - 'estree' | - 'exportDefaultFrom' | - 'exportNamespaceFrom' | // deprecated - 'flow' | - 'flowComments' | - 'functionBind' | - 'functionSent' | - 'importMeta' | - 'jsx' | - 'logicalAssignment' | - 'importAssertions' | - 'moduleStringNames' | - 'nullishCoalescingOperator' | - 'numericSeparator' | - 'objectRestSpread' | - 'optionalCatchBinding' | - 'optionalChaining' | - 'partialApplication' | - 'pipelineOperator' | - 'placeholders' | - 'privateIn' | - 'throwExpressions' | - 'topLevelAwait' | - 'typescript' | - 'v8intrinsic' | - ParserPluginWithOptions; + | "asyncGenerators" + | "bigInt" + | "classPrivateMethods" + | "classPrivateProperties" + | "classProperties" + | "classStaticBlock" + | "decimal" + | "decorators" + | "decorators-legacy" + | "doExpressions" + | "dynamicImport" + | "estree" + | "exportDefaultFrom" + | "exportNamespaceFrom" // deprecated + | "flow" + | "flowComments" + | "functionBind" + | "functionSent" + | "importMeta" + | "jsx" + | "logicalAssignment" + | "importAssertions" + | "moduleStringNames" + | "nullishCoalescingOperator" + | "numericSeparator" + | "objectRestSpread" + | "optionalCatchBinding" + | "optionalChaining" + | "partialApplication" + | "pipelineOperator" + | "placeholders" + | "privateIn" + | "throwExpressions" + | "topLevelAwait" + | "typescript" + | "v8intrinsic" + | ParserPluginWithOptions; export type ParserPluginWithOptions = - ['decorators', DecoratorsPluginOptions] | - ['pipelineOperator', PipelineOperatorPluginOptions] | - ['flow', FlowPluginOptions]; + | ["decorators", DecoratorsPluginOptions] + | ["pipelineOperator", PipelineOperatorPluginOptions] + | ["flow", FlowPluginOptions]; export interface DecoratorsPluginOptions { - decoratorsBeforeExport?: boolean; + decoratorsBeforeExport?: boolean; } export interface PipelineOperatorPluginOptions { - proposal: 'minimal' | 'smart'; + proposal: "minimal" | "smart"; } export interface FlowPluginOptions { - all?: boolean; + all?: boolean; } diff --git a/packages/babel-template/src/builder.js b/packages/babel-template/src/builder.ts similarity index 86% rename from packages/babel-template/src/builder.js rename to packages/babel-template/src/builder.ts index b299e2e7b6d9..7040f81595e2 100644 --- a/packages/babel-template/src/builder.js +++ b/packages/babel-template/src/builder.ts @@ -1,12 +1,5 @@ -// @flow - -import { - merge, - validate, - type TemplateOpts, - type PublicOpts, - type PublicReplacements, -} from "./options"; +import { merge, validate } from "./options"; +import type { TemplateOpts, PublicOpts, PublicReplacements } from "./options"; import type { Formatter } from "./formatters"; import stringTemplate from "./string"; @@ -14,20 +7,22 @@ import literalTemplate from "./literal"; export type TemplateBuilder = { // Build a new builder, merging the given options with the previous ones. - (opts: PublicOpts): TemplateBuilder, + (opts: PublicOpts): TemplateBuilder; // Building from a string produces an AST builder function by default. - (tpl: string, opts: ?PublicOpts): (?PublicReplacements) => T, + (tpl: string, opts?: PublicOpts): (replacements?: PublicReplacements) => T; // Building from a template literal produces an AST builder function by default. - (tpl: Array, ...args: Array): (?PublicReplacements) => T, + (tpl: TemplateStringsArray, ...args: Array): ( + replacements?: PublicReplacements, + ) => T; // Allow users to explicitly create templates that produce ASTs, skipping // the need for an intermediate function. ast: { - (tpl: string, opts: ?PublicOpts): T, - (tpl: Array, ...args: Array): T, - }, + (tpl: string, opts?: PublicOpts): T; + (tpl: TemplateStringsArray, ...args: Array): T; + }; }; // Prebuild the options that will be used when parsing a `.ast` template. @@ -69,7 +64,7 @@ export default function createTemplateBuilder( ); } throw new Error(`Unexpected template param ${typeof tpl}`); - }: Function), + }) as TemplateBuilder, { ast: (tpl, ...args) => { if (typeof tpl === "string") { @@ -98,7 +93,9 @@ export default function createTemplateBuilder( ); } -function extendedTrace(fn: Arg => Result): Arg => Result { +function extendedTrace( + fn: (_: Arg) => Result, +): (_: Arg) => Result { // Since we lazy parse the template, we get the current stack so we have the // original stack to append if it errors when parsing let rootStack = ""; diff --git a/packages/babel-template/src/formatters.js b/packages/babel-template/src/formatters.js deleted file mode 100644 index 4feb1d5484e4..000000000000 --- a/packages/babel-template/src/formatters.js +++ /dev/null @@ -1,75 +0,0 @@ -// @flow - -export type Formatter = { - code: string => string, - validate: BabelNodeFile => void, - unwrap: BabelNodeFile => T, -}; - -function makeStatementFormatter( - fn: (Array) => T, -): Formatter { - return { - // We need to prepend a ";" to force statement parsing so that - // ExpressionStatement strings won't be parsed as directives. - // Alongside that, we also prepend a comment so that when a syntax error - // is encountered, the user will be less likely to get confused about - // where the random semicolon came from. - code: str => `/* @babel/template */;\n${str}`, - validate: () => {}, - unwrap: (ast: BabelNodeFile): T => { - return fn(ast.program.body.slice(1)); - }, - }; -} - -export const smart: Formatter< - Array | BabelNodeStatement, -> = makeStatementFormatter(body => { - if (body.length > 1) { - return body; - } else { - return body[0]; - } -}); - -export const statements: Formatter< - Array, -> = makeStatementFormatter(body => body); - -export const statement: Formatter = makeStatementFormatter( - body => { - // We do this validation when unwrapping since the replacement process - // could have added or removed statements. - if (body.length === 0) { - throw new Error("Found nothing to return."); - } - if (body.length > 1) { - throw new Error("Found multiple statements but wanted one"); - } - - return body[0]; - }, -); - -export const expression: Formatter = { - code: str => `(\n${str}\n)`, - validate: ({ program }) => { - if (program.body.length > 1) { - throw new Error("Found multiple statements but wanted one"); - } - // $FlowFixMe - const expression = program.body[0].expression; - if (expression.start === 0) { - throw new Error("Parse result included parens."); - } - }, - // $FlowFixMe - unwrap: ast => ast.program.body[0].expression, -}; - -export const program: Formatter = { - code: str => str, - validate: () => {}, - unwrap: ast => ast.program, -}; diff --git a/packages/babel-template/src/formatters.ts b/packages/babel-template/src/formatters.ts new file mode 100644 index 000000000000..3a34fa68a2a4 --- /dev/null +++ b/packages/babel-template/src/formatters.ts @@ -0,0 +1,70 @@ +import * as t from "@babel/types"; + +export type Formatter = { + code: (source: string) => string; + validate: (ast: t.File) => void; + unwrap: (ast: t.File) => T; +}; + +function makeStatementFormatter( + fn: (statements: Array) => T, +): Formatter { + return { + // We need to prepend a ";" to force statement parsing so that + // ExpressionStatement strings won't be parsed as directives. + // Alongside that, we also prepend a comment so that when a syntax error + // is encountered, the user will be less likely to get confused about + // where the random semicolon came from. + code: str => `/* @babel/template */;\n${str}`, + validate: () => {}, + unwrap: (ast: t.File): T => { + return fn(ast.program.body.slice(1)); + }, + }; +} + +export const smart = makeStatementFormatter(body => { + if (body.length > 1) { + return body; + } else { + return body[0]; + } +}); + +export const statements = makeStatementFormatter(body => body); + +export const statement = makeStatementFormatter(body => { + // We do this validation when unwrapping since the replacement process + // could have added or removed statements. + if (body.length === 0) { + throw new Error("Found nothing to return."); + } + if (body.length > 1) { + throw new Error("Found multiple statements but wanted one"); + } + + return body[0]; +}); + +export const expression: Formatter = { + code: str => `(\n${str}\n)`, + validate: ast => { + if (ast.program.body.length > 1) { + throw new Error("Found multiple statements but wanted one"); + } + if (expression.unwrap(ast).start === 0) { + throw new Error("Parse result included parens."); + } + }, + unwrap: ({ program }) => { + const [stmt] = program.body; + t.assertExpressionStatement(stmt); + return stmt.expression; + }, +}; + +export const program: Formatter = { + code: str => str, + validate: () => {}, + unwrap: ast => ast.program, +}; diff --git a/packages/babel-template/src/index.js b/packages/babel-template/src/index.js deleted file mode 100644 index 7322d9ab99f2..000000000000 --- a/packages/babel-template/src/index.js +++ /dev/null @@ -1,31 +0,0 @@ -// @flow - -import * as formatters from "./formatters"; -import createTemplateBuilder from "./builder"; - -export const smart = createTemplateBuilder<*>(formatters.smart); -export const statement = createTemplateBuilder<*>(formatters.statement); -export const statements = createTemplateBuilder<*>(formatters.statements); -export const expression = createTemplateBuilder<*>(formatters.expression); -export const program = createTemplateBuilder<*>(formatters.program); - -type DefaultTemplateBuilder = typeof smart & { - smart: typeof smart, - statement: typeof statement, - statements: typeof statements, - expression: typeof expression, - program: typeof program, - ast: typeof smart.ast, -}; - -export default Object.assign( - ((smart.bind(undefined): any): DefaultTemplateBuilder), - { - smart, - statement, - statements, - expression, - program, - ast: smart.ast, - }, -); diff --git a/packages/babel-template/src/index.ts b/packages/babel-template/src/index.ts new file mode 100644 index 000000000000..84d2c0e3a408 --- /dev/null +++ b/packages/babel-template/src/index.ts @@ -0,0 +1,25 @@ +import * as formatters from "./formatters"; +import createTemplateBuilder from "./builder"; + +export const smart = createTemplateBuilder(formatters.smart); +export const statement = createTemplateBuilder(formatters.statement); +export const statements = createTemplateBuilder(formatters.statements); +export const expression = createTemplateBuilder(formatters.expression); +export const program = createTemplateBuilder(formatters.program); + +type DefaultTemplateBuilder = typeof smart & { + smart: typeof smart; + statement: typeof statement; + statements: typeof statements; + expression: typeof expression; + program: typeof program; +}; + +export default Object.assign(smart.bind(undefined) as DefaultTemplateBuilder, { + smart, + statement, + statements, + expression, + program, + ast: smart.ast, +}); diff --git a/packages/babel-template/src/literal.js b/packages/babel-template/src/literal.ts similarity index 85% rename from packages/babel-template/src/literal.js rename to packages/babel-template/src/literal.ts index 0cc7415e72fa..c436edcbd8db 100644 --- a/packages/babel-template/src/literal.js +++ b/packages/babel-template/src/literal.ts @@ -1,7 +1,6 @@ -// @flow - import type { Formatter } from "./formatters"; -import { normalizeReplacements, type TemplateOpts } from "./options"; +import type { TemplateReplacements, TemplateOpts } from "./options"; +import { normalizeReplacements } from "./options"; import parseAndBuildMetadata from "./parse"; import populatePlaceholders from "./populate"; @@ -9,16 +8,16 @@ export default function literalTemplate( formatter: Formatter, tpl: Array, opts: TemplateOpts, -): (Array) => mixed => T { +): (_: Array) => (_: unknown) => T { const { metadata, names } = buildLiteralData(formatter, tpl, opts); - return (arg: Array) => { - const defaultReplacements = arg.reduce((acc, replacement, i) => { - acc[names[i]] = replacement; - return acc; - }, {}); + return arg => { + const defaultReplacements: TemplateReplacements = {}; + arg.forEach((replacement, i) => { + defaultReplacements[names[i]] = replacement; + }); - return (arg: mixed) => { + return (arg: unknown) => { const replacements = normalizeReplacements(arg); if (replacements) { @@ -88,7 +87,7 @@ function buildLiteralData( function buildTemplateCode( tpl: Array, prefix: string, -): { names: Array, code: string } { +): { names: Array; code: string } { const names = []; let code = tpl[0]; diff --git a/packages/babel-template/src/options.js b/packages/babel-template/src/options.ts similarity index 83% rename from packages/babel-template/src/options.js rename to packages/babel-template/src/options.ts index b1c6f38a6e86..8be69dcc69f3 100644 --- a/packages/babel-template/src/options.js +++ b/packages/babel-template/src/options.ts @@ -1,6 +1,4 @@ -// @flow - -import type { Options as ParserOpts } from "@babel/parser/src/options"; +import type { ParserOptions as ParserOpts } from "@babel/parser"; export type { ParserOpts }; @@ -15,8 +13,7 @@ export type PublicOpts = { * * This option can be used when using %%foo%% style placeholders. */ - placeholderWhitelist?: ?Set, - + placeholderWhitelist?: Set; /** * A pattern to search for when looking for Identifier and StringLiteral * nodes that can be replaced. @@ -28,30 +25,28 @@ export type PublicOpts = { * * This option can be used when using %%foo%% style placeholders. */ - placeholderPattern?: ?(RegExp | false), - + placeholderPattern?: RegExp | false; /** * 'true' to pass through comments from the template into the resulting AST, * or 'false' to automatically discard comments. Defaults to 'false'. */ - preserveComments?: ?boolean, - + preserveComments?: boolean; /** * 'true' to use %%foo%% style placeholders, 'false' to use legacy placeholders * described by placeholderPattern or placeholderWhitelist. * When it is not set, it behaves as 'true' if there are syntactic placeholders, * otherwise as 'false'. */ - syntacticPlaceholders?: ?boolean, + syntacticPlaceholders?: boolean | null; }; -export type TemplateOpts = {| - parser: ParserOpts, - placeholderWhitelist: Set | void, - placeholderPattern: RegExp | false | void, - preserveComments: boolean | void, - syntacticPlaceholders: boolean | void, -|}; +export type TemplateOpts = { + parser: ParserOpts; + placeholderWhitelist?: Set; + placeholderPattern?: RegExp | false; + preserveComments?: boolean; + syntacticPlaceholders?: boolean; +}; export function merge(a: TemplateOpts, b: TemplateOpts): TemplateOpts { const { @@ -73,7 +68,7 @@ export function merge(a: TemplateOpts, b: TemplateOpts): TemplateOpts { }; } -export function validate(opts: mixed): TemplateOpts { +export function validate(opts: unknown): TemplateOpts { if (opts != null && typeof opts !== "object") { throw new Error("Unknown template options."); } @@ -84,7 +79,7 @@ export function validate(opts: mixed): TemplateOpts { preserveComments, syntacticPlaceholders, ...parser - } = opts || {}; + } = opts || ({} as any); if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) { throw new Error( @@ -137,11 +132,11 @@ export function validate(opts: mixed): TemplateOpts { }; } -export type PublicReplacements = { [string]: mixed } | Array; -export type TemplateReplacements = { [string]: mixed } | void; +export type PublicReplacements = { [x: string]: unknown } | Array; +export type TemplateReplacements = { [x: string]: unknown } | void; export function normalizeReplacements( - replacements: mixed, + replacements: unknown, ): TemplateReplacements { if (Array.isArray(replacements)) { return replacements.reduce((acc, replacement, i) => { @@ -149,7 +144,7 @@ export function normalizeReplacements( return acc; }, {}); } else if (typeof replacements === "object" || replacements == null) { - return (replacements: any) || undefined; + return (replacements as any) || undefined; } throw new Error( diff --git a/packages/babel-template/src/parse.js b/packages/babel-template/src/parse.ts similarity index 78% rename from packages/babel-template/src/parse.js rename to packages/babel-template/src/parse.ts index 3a0b6596d402..55af745271c1 100644 --- a/packages/babel-template/src/parse.js +++ b/packages/babel-template/src/parse.ts @@ -1,4 +1,3 @@ -// @flow import * as t from "@babel/types"; import type { TraversalAncestors, TraversalHandler } from "@babel/types"; import { parse } from "@babel/parser"; @@ -7,18 +6,18 @@ import type { TemplateOpts, ParserOpts } from "./options"; import type { Formatter } from "./formatters"; export type Metadata = { - ast: BabelNodeFile, - placeholders: Array, - placeholderNames: Set, + ast: t.File; + placeholders: Array; + placeholderNames: Set; }; type PlaceholderType = "string" | "param" | "statement" | "other"; -export type Placeholder = {| - name: string, - resolve: BabelNodeFile => { parent: BabelNode, key: string, index?: number }, - type: PlaceholderType, - isDuplicate: boolean, -|}; +export type Placeholder = { + name: string; + resolve: (a: t.File) => { parent: t.Node; key: string; index?: number }; + type: PlaceholderType; + isDuplicate: boolean; +}; const PATTERN = /^[_$A-Z0-9]+$/; @@ -44,15 +43,15 @@ export default function parseAndBuildMetadata( const syntactic = { placeholders: [], - placeholderNames: new Set(), + placeholderNames: new Set(), }; const legacy = { placeholders: [], - placeholderNames: new Set(), + placeholderNames: new Set(), }; const isLegacyRef = { value: undefined }; - t.traverse(ast, (placeholderVisitorHandler: TraversalHandler<*>), { + t.traverse(ast, placeholderVisitorHandler as TraversalHandler, { syntactic, legacy, isLegacyRef, @@ -68,11 +67,11 @@ export default function parseAndBuildMetadata( } function placeholderVisitorHandler( - node: BabelNode, + node: t.Node, ancestors: TraversalAncestors, state: MetadataState, ) { - let name; + let name: string; if (t.isPlaceholder(node)) { if (state.syntacticPlaceholders === false) { @@ -81,16 +80,16 @@ function placeholderVisitorHandler( "'.syntacticPlaceholders' is false.", ); } else { - name = ((node: any).name: BabelNodeIdentifier).name; + name = node.name.name; state.isLegacyRef.value = false; } } else if (state.isLegacyRef.value === false || state.syntacticPlaceholders) { return; } else if (t.isIdentifier(node) || t.isJSXIdentifier(node)) { - name = ((node: any): BabelNodeIdentifier).name; + name = node.name; state.isLegacyRef.value = true; } else if (t.isStringLiteral(node)) { - name = ((node: any): BabelNodeStringLiteral).value; + name = node.value; state.isLegacyRef.value = true; } else { return; @@ -156,15 +155,15 @@ function placeholderVisitorHandler( placeholderNames.add(name); } -function resolveAncestors(ast: BabelNodeFile, ancestors: TraversalAncestors) { - let parent: BabelNode = ast; +function resolveAncestors(ast: t.File, ancestors: TraversalAncestors) { + let parent: t.Node = ast; for (let i = 0; i < ancestors.length - 1; i++) { const { key, index } = ancestors[i]; if (index === undefined) { - parent = (parent: any)[key]; + parent = (parent as any)[key]; } else { - parent = (parent: any)[key][index]; + parent = (parent as any)[key][index]; } } @@ -175,24 +174,26 @@ function resolveAncestors(ast: BabelNodeFile, ancestors: TraversalAncestors) { type MetadataState = { syntactic: { - placeholders: Array, - placeholderNames: Set, - }, + placeholders: Array; + placeholderNames: Set; + }; legacy: { - placeholders: Array, - placeholderNames: Set, - }, - isLegacyRef: { value: boolean | void }, - placeholderWhitelist: Set | void, - placeholderPattern: RegExp | false | void, - syntacticPlaceholders: boolean | void, + placeholders: Array; + placeholderNames: Set; + }; + isLegacyRef: { + value?: boolean; + }; + placeholderWhitelist?: Set; + placeholderPattern?: RegExp | false; + syntacticPlaceholders?: boolean; }; function parseWithCodeFrame( code: string, parserOpts: ParserOpts, syntacticPlaceholders?: boolean, -): BabelNodeFile { +): t.File { const plugins = (parserOpts.plugins || []).slice(); if (syntacticPlaceholders !== false) { plugins.push("placeholders"); @@ -207,7 +208,6 @@ function parseWithCodeFrame( }; try { - // $FlowFixMe - The parser AST is not the same type as the babel-types type. return parse(code, parserOpts); } catch (err) { const loc = err.loc; diff --git a/packages/babel-template/src/populate.js b/packages/babel-template/src/populate.ts similarity index 92% rename from packages/babel-template/src/populate.js rename to packages/babel-template/src/populate.ts index 90b13853ba67..bca35c3e0120 100644 --- a/packages/babel-template/src/populate.js +++ b/packages/babel-template/src/populate.ts @@ -1,4 +1,3 @@ -// @flow import * as t from "@babel/types"; import type { TemplateReplacements } from "./options"; @@ -7,7 +6,7 @@ import type { Metadata, Placeholder } from "./parse"; export default function populatePlaceholders( metadata: Metadata, replacements: TemplateReplacements, -): BabelNodeFile { +): t.File { const ast = t.cloneNode(metadata.ast); if (replacements) { @@ -55,7 +54,7 @@ export default function populatePlaceholders( function applyReplacement( placeholder: Placeholder, - ast: BabelNodeFile, + ast: t.File, replacement: any, ) { // Track inserted nodes and clone them if they are inserted more than @@ -86,7 +85,7 @@ function applyReplacement( } else if (typeof replacement === "string") { replacement = t.expressionStatement(t.identifier(replacement)); } else if (!t.isStatement(replacement)) { - replacement = t.expressionStatement((replacement: any)); + replacement = t.expressionStatement(replacement as any); } } else { if (replacement && !Array.isArray(replacement)) { @@ -94,7 +93,7 @@ function applyReplacement( replacement = t.identifier(replacement); } if (!t.isStatement(replacement)) { - replacement = t.expressionStatement((replacement: any)); + replacement = t.expressionStatement(replacement as any); } } } @@ -116,9 +115,9 @@ function applyReplacement( if (index === undefined) { t.validate(parent, key, replacement); - (parent: any)[key] = replacement; + (parent as any)[key] = replacement; } else { - const items: Array = (parent: any)[key].slice(); + const items: Array = (parent as any)[key].slice(); if (placeholder.type === "statement" || placeholder.type === "param") { if (replacement == null) { @@ -133,6 +132,6 @@ function applyReplacement( } t.validate(parent, key, items); - (parent: any)[key] = items; + (parent as any)[key] = items; } } diff --git a/packages/babel-template/src/string.js b/packages/babel-template/src/string.ts similarity index 76% rename from packages/babel-template/src/string.js rename to packages/babel-template/src/string.ts index 3fbf7df41907..1f8ad4c9f783 100644 --- a/packages/babel-template/src/string.js +++ b/packages/babel-template/src/string.ts @@ -1,6 +1,6 @@ -// @flow import type { Formatter } from "./formatters"; -import { normalizeReplacements, type TemplateOpts } from "./options"; +import type { TemplateOpts } from "./options"; +import { normalizeReplacements } from "./options"; import parseAndBuildMetadata from "./parse"; import populatePlaceholders from "./populate"; @@ -8,12 +8,12 @@ export default function stringTemplate( formatter: Formatter, code: string, opts: TemplateOpts, -): mixed => T { +): (arg?: unknown) => T { code = formatter.code(code); let metadata; - return (arg?: mixed) => { + return (arg?: unknown) => { const replacements = normalizeReplacements(arg); if (!metadata) metadata = parseAndBuildMetadata(formatter, code, opts); diff --git a/packages/babel-types/package.json b/packages/babel-types/package.json index b81e7e09887a..e566d398115d 100644 --- a/packages/babel-types/package.json +++ b/packages/babel-types/package.json @@ -15,6 +15,13 @@ }, "main": "lib/index.js", "types": "lib/index.d.ts", + "typesVersions": { + ">=3.7": { + "lib/index.d.ts": [ + "lib/index-ts3.7.d.ts" + ] + } + }, "dependencies": { "@babel/helper-validator-identifier": "workspace:^7.10.4", "lodash": "^4.17.19", diff --git a/packages/babel-types/scripts/generators/typescript.js b/packages/babel-types/scripts/generators/typescript.js index 405d2e776aee..07c80082cac8 100644 --- a/packages/babel-types/scripts/generators/typescript.js +++ b/packages/babel-types/scripts/generators/typescript.js @@ -4,6 +4,15 @@ const t = require("../../"); const stringifyValidator = require("../utils/stringifyValidator"); const toFunctionName = require("../utils/toFunctionName"); +// For backward compat, we cannot use TS 3.7 syntax in published packages +const ts3_7 = process.argv.includes("--ts3.7") + ? (code, ...substitutions) => template(code, substitutions) + : () => ""; +const template = (strings, substitutions) => + strings + .slice(1) + .reduce((res, str, i) => res + substitutions[i] + str, strings[0]); + let code = `// NOTE: This file is autogenerated. Do not modify. // See packages/babel-types/scripts/generators/typescript.js for script used. @@ -130,7 +139,7 @@ for (const typeName of t.TYPES) { `export function is${typeName}(node: object | null | undefined, opts?: object | null): ${result};`, // TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations // eslint-disable-next-line max-len - `// export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${ + ts3_7`export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${ result === "boolean" ? "node" : result };` ); @@ -138,8 +147,7 @@ for (const typeName of t.TYPES) { lines.push( // assert/ - // Commented out as this declaration requires TypeScript 3.7 (what do?) - `// export function assertNode(obj: any): asserts obj is Node`, + ts3_7`export function assertNode(obj: any): asserts obj is Node`, // builders/ // eslint-disable-next-line max-len diff --git a/scripts/generators/tsconfig.js b/scripts/generators/tsconfig.js new file mode 100644 index 000000000000..b4605ffc10cb --- /dev/null +++ b/scripts/generators/tsconfig.js @@ -0,0 +1,71 @@ +"use strict"; + +const path = require("path"); +const fs = require("fs"); + +const root = path.resolve(__dirname, "../../"); + +const tsPkgs = fs + .readdirSync(path.join(root, "packages")) + .filter(name => name.startsWith("babel-")) + .map(name => ({ + name: name.replace(/^babel-/, "@babel/"), + dir: path.resolve(root, "packages", name), + })) + .filter(({ dir }) => { + try { + fs.statSync(path.join(dir, "src", "index.ts")); + return true; + } catch { + return false; + } + }); + +for (const { dir } of tsPkgs) { + const pkg = require(`${dir}/package.json`); + + const references = []; + for (const dep of Object.keys(pkg.dependencies)) { + if (!dep.startsWith("@babel/")) continue; + for (const { name, dir: depDir } of tsPkgs) { + if (name === dep) { + references.push({ path: path.relative(dir, depDir) }); + break; + } + } + } + + fs.writeFileSync( + path.resolve(dir, "tsconfig.json"), + JSON.stringify( + { + extends: "../../tsconfig.base.json", + compilerOptions: { + // Until we have converted every package, we cannot store + // .d.ts files inside lib/ because it causes conflicts + // with Babel-related type definitions in node_modules/@types + outDir: "./dts", + rootDir: "./src", + }, + include: ["./src/**/*"], + references, + }, + null, + 2 + ) + ); +} + +fs.writeFileSync( + path.resolve(root, `tsconfig.json`), + JSON.stringify( + { + files: [], + references: tsPkgs.map(({ dir }) => ({ + path: path.relative(root, dir), + })), + }, + null, + 2 + ) +); diff --git a/scripts/rollup-plugin-babel-source.js b/scripts/rollup-plugin-babel-source.js index 8527b10dff94..1c131c804e89 100644 --- a/scripts/rollup-plugin-babel-source.js +++ b/scripts/rollup-plugin-babel-source.js @@ -81,13 +81,21 @@ module.exports = function () { ? packageJson["browser"] : packageJson["main"]; - return path.normalize( + const asJS = path.normalize( path.join( packageFolder, // replace lib with src in the package.json entry filename.replace(/^(\.\/)?lib\//, "src/") ) ); + const asTS = asJS.replace(/\.js$/, ".ts"); + + try { + fs.statSync(asTS); + return asTS; + } catch { + return asJS; + } }, }; }; diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 000000000000..4133ecd285e8 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "lib": [ + "esnext" + ], + "emitDeclarationOnly": true, + "composite": true, + "moduleResolution": "node", + "esModuleInterop": true, + "isolatedModules": true, + "skipLibCheck": true, + "resolveJsonModule": true + } +} diff --git a/yarn.lock b/yarn.lock index cbcf7dd00ec8..432f6b84ff6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -233,14 +233,14 @@ __metadata: languageName: unknown linkType: soft -"@babel/generator@npm:^7.12.0": - version: 7.12.0 - resolution: "@babel/generator@npm:7.12.0" +"@babel/generator@npm:^7.12.0, @babel/generator@npm:^7.12.5": + version: 7.12.5 + resolution: "@babel/generator@npm:7.12.5" dependencies: - "@babel/types": ^7.12.0 + "@babel/types": ^7.12.5 jsesc: ^2.5.1 source-map: ^0.5.0 - checksum: e3aa0dfbe91cac7f21e796969a37effeb63006f66e568e90d371fc3592c47c9430f2afc6f14a53657798e401c99f9335470ee4fa1001ea7778232f613961ab97 + checksum: 7706cb3d29060e6dfcdbc982ded9a02f0bda36329cc35aabc6b3f9f30ef7b3b3bcaba51c24714663f3ea9529994cd3461ab8a664b26398208b9b9a96476bf43c languageName: node linkType: hard @@ -358,19 +358,18 @@ __metadata: languageName: unknown linkType: soft -"@babel/helper-create-class-features-plugin@npm:^7.10.4": - version: 7.10.5 - resolution: "@babel/helper-create-class-features-plugin@npm:7.10.5" +"@babel/helper-create-class-features-plugin@npm:^7.10.4, @babel/helper-create-class-features-plugin@npm:^7.12.1": + version: 7.12.1 + resolution: "@babel/helper-create-class-features-plugin@npm:7.12.1" dependencies: "@babel/helper-function-name": ^7.10.4 - "@babel/helper-member-expression-to-functions": ^7.10.5 + "@babel/helper-member-expression-to-functions": ^7.12.1 "@babel/helper-optimise-call-expression": ^7.10.4 - "@babel/helper-plugin-utils": ^7.10.4 - "@babel/helper-replace-supers": ^7.10.4 + "@babel/helper-replace-supers": ^7.12.1 "@babel/helper-split-export-declaration": ^7.10.4 peerDependencies: "@babel/core": ^7.0.0 - checksum: ba8fb0f7b7788d0fde2341314a86d0d5705ed17537eba1e319bb0e532125c5b97fc142633ae1605615be9f45cb6cbf19879c13e626610ecd3be1821d651a1423 + checksum: d686eae70dc985b5e0dae85b7ec690930939b564be7f2c09ca2838a52f562f5753fa5d8a12f7305303597f9f8658d51cb36ec71e6e234b1d1385a36c632ea61f languageName: node linkType: hard @@ -530,12 +529,12 @@ __metadata: languageName: unknown linkType: soft -"@babel/helper-member-expression-to-functions@npm:^7.10.5, @babel/helper-member-expression-to-functions@npm:^7.12.0": - version: 7.12.0 - resolution: "@babel/helper-member-expression-to-functions@npm:7.12.0" +"@babel/helper-member-expression-to-functions@npm:^7.12.1": + version: 7.12.1 + resolution: "@babel/helper-member-expression-to-functions@npm:7.12.1" dependencies: - "@babel/types": ^7.12.0 - checksum: 9f849d023bc03585609610523772bbcffcf370b88ac921bc587e69c91d010c6312d0977e00c18b771cba48ea935cc71f2e72df08e13b047c50f2278578fdcfc9 + "@babel/types": ^7.12.1 + checksum: ae0cd0594bcc0343663747b28aa3433a312164eab259f919d184d39aed60dc2602b4cf0c7e287a22583c244cfc467b9097a289c1c4fd383f435ad10642c6a3d6 languageName: node linkType: hard @@ -676,15 +675,15 @@ __metadata: languageName: unknown linkType: soft -"@babel/helper-replace-supers@npm:^7.10.4, @babel/helper-replace-supers@npm:^7.12.0": - version: 7.12.0 - resolution: "@babel/helper-replace-supers@npm:7.12.0" +"@babel/helper-replace-supers@npm:^7.10.4, @babel/helper-replace-supers@npm:^7.12.0, @babel/helper-replace-supers@npm:^7.12.1": + version: 7.12.5 + resolution: "@babel/helper-replace-supers@npm:7.12.5" dependencies: - "@babel/helper-member-expression-to-functions": ^7.12.0 + "@babel/helper-member-expression-to-functions": ^7.12.1 "@babel/helper-optimise-call-expression": ^7.10.4 - "@babel/traverse": ^7.12.0 - "@babel/types": ^7.12.0 - checksum: 4846d88f771d604436c2c7a197d8608b361e883672c1904d9f987b0d13e234eb53f88a026de1c0f85fed1c966401abb1a20a2f40b5567f2d85854c8563549880 + "@babel/traverse": ^7.12.5 + "@babel/types": ^7.12.5 + checksum: 5a9ac871de38e65128e082bcca925298a4dd1501b1b79d79ebf7fc3c03490dcc1e397d582f513543f908f962dcb161a0ce4d968423b0c209c4321487bf2d5ec9 languageName: node linkType: hard @@ -890,12 +889,12 @@ __metadata: languageName: unknown linkType: soft -"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.10.4, @babel/parser@npm:^7.12.0": - version: 7.12.0 - resolution: "@babel/parser@npm:7.12.0" +"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.10.4, @babel/parser@npm:^7.12.0, @babel/parser@npm:^7.12.5": + version: 7.12.5 + resolution: "@babel/parser@npm:7.12.5" bin: parser: ./bin/babel-parser.js - checksum: 0b656c02c810b485481ace5258bd56a008f6e31c14711818c81b7446b6d639c4c1f21c7243072d28a356274bb83d9d81c9eeff12ed3419fcdff8362551c2822b + checksum: ff03d2389e32e3710c759d7bbcffc2d2e0637498e3a36aeaa0dbf961c48adb7027c393d0458247e54e24fed66ce0ea00e3e8d63089d22931e4175ee398727c15 languageName: node linkType: hard @@ -1763,6 +1762,17 @@ __metadata: languageName: unknown linkType: soft +"@babel/plugin-syntax-typescript@npm:^7.12.1": + version: 7.12.1 + resolution: "@babel/plugin-syntax-typescript@npm:7.12.1" + dependencies: + "@babel/helper-plugin-utils": ^7.10.4 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 37bdb828915d9193d5fc3b877fb479f1cef6ea3f1cfaa18908170fe23af043ba59d7bc723d3e27067b879e486f16e418d602d7212a7a1e93125bf80339c39668 + languageName: node + linkType: hard + "@babel/plugin-syntax-typescript@workspace:*, @babel/plugin-syntax-typescript@workspace:^7.12.1, @babel/plugin-syntax-typescript@workspace:packages/babel-plugin-syntax-typescript": version: 0.0.0-use.local resolution: "@babel/plugin-syntax-typescript@workspace:packages/babel-plugin-syntax-typescript" @@ -2805,6 +2815,19 @@ __metadata: languageName: unknown linkType: soft +"@babel/plugin-transform-typescript@npm:^7.12.1": + version: 7.12.1 + resolution: "@babel/plugin-transform-typescript@npm:7.12.1" + dependencies: + "@babel/helper-create-class-features-plugin": ^7.12.1 + "@babel/helper-plugin-utils": ^7.10.4 + "@babel/plugin-syntax-typescript": ^7.12.1 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: d93737e2350d0f7c36726c43af64ed4af566e67fd38400faf7f9057ede62eef4fa99235228167b27150e03b86aa53c2ef9f0ea346a02ad9a3070c147aa5e732d + languageName: node + linkType: hard + "@babel/plugin-transform-typescript@workspace:*, @babel/plugin-transform-typescript@workspace:^7.12.1, @babel/plugin-transform-typescript@workspace:packages/babel-plugin-transform-typescript": version: 0.0.0-use.local resolution: "@babel/plugin-transform-typescript@workspace:packages/babel-plugin-transform-typescript" @@ -3092,6 +3115,18 @@ __metadata: languageName: unknown linkType: soft +"@babel/preset-typescript@npm:^7.12.1": + version: 7.12.1 + resolution: "@babel/preset-typescript@npm:7.12.1" + dependencies: + "@babel/helper-plugin-utils": ^7.10.4 + "@babel/plugin-transform-typescript": ^7.12.1 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 730eb743a4367db204c229183a3c2d669caa4f5234d98196c39368fc54f2cadd20a3d55f71104ebec8bc17cf3236b784f2737cac9ae4bb57b250cd1c609aabf9 + languageName: node + linkType: hard + "@babel/preset-typescript@workspace:*, @babel/preset-typescript@workspace:packages/babel-preset-typescript": version: 0.0.0-use.local resolution: "@babel/preset-typescript@workspace:packages/babel-preset-typescript" @@ -3310,20 +3345,20 @@ __metadata: languageName: unknown linkType: soft -"@babel/traverse@npm:^7.0.0, @babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.10.4, @babel/traverse@npm:^7.12.0": - version: 7.12.0 - resolution: "@babel/traverse@npm:7.12.0" +"@babel/traverse@npm:^7.0.0, @babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.10.4, @babel/traverse@npm:^7.12.0, @babel/traverse@npm:^7.12.5": + version: 7.12.5 + resolution: "@babel/traverse@npm:7.12.5" dependencies: "@babel/code-frame": ^7.10.4 - "@babel/generator": ^7.12.0 + "@babel/generator": ^7.12.5 "@babel/helper-function-name": ^7.10.4 "@babel/helper-split-export-declaration": ^7.11.0 - "@babel/parser": ^7.12.0 - "@babel/types": ^7.12.0 + "@babel/parser": ^7.12.5 + "@babel/types": ^7.12.5 debug: ^4.1.0 globals: ^11.1.0 lodash: ^4.17.19 - checksum: b91d87998e6d6d6b6bc5ba3e4bd81388a4c26d78951eab0d9db2c8dcc37b04ccd03d84915a095b982df613a8d912433b7dcb967df7f0af04deb70ec1eacfffe2 + checksum: 86b9e0edbb61aeda7273920b3e99e9ae26aa61c77481081429c8340695166fdb2ce3afc2504d78e55a03f88a4e83fd8a651d569a948f3c8a4092d1d173facb8b languageName: node linkType: hard @@ -3344,14 +3379,14 @@ __metadata: languageName: unknown linkType: soft -"@babel/types@npm:^7.0.0, @babel/types@npm:^7.10.4, @babel/types@npm:^7.10.5, @babel/types@npm:^7.11.0, @babel/types@npm:^7.12.0, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3": - version: 7.12.0 - resolution: "@babel/types@npm:7.12.0" +"@babel/types@npm:^7.0.0, @babel/types@npm:^7.10.4, @babel/types@npm:^7.10.5, @babel/types@npm:^7.11.0, @babel/types@npm:^7.12.0, @babel/types@npm:^7.12.1, @babel/types@npm:^7.12.5, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3": + version: 7.12.6 + resolution: "@babel/types@npm:7.12.6" dependencies: "@babel/helper-validator-identifier": ^7.10.4 lodash: ^4.17.19 to-fast-properties: ^2.0.0 - checksum: 61e5682d3a41e7a7d2842f62d5b25f88cc81490715f3b935abb8a10480199a9f5a725d206417e1d6f567da95b6a121cd1893b52ee5b3ea77d9ecca323c23eb41 + checksum: e8d02f859c16c8ae941a1eb84954189eacdd9488c8f9ad54c29dedf2bf8456f45c7fe401c54ea2c4d45d890d865aaac0283a78b62a87f796e92078eac49aa040 languageName: node linkType: hard @@ -3969,6 +4004,43 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/eslint-plugin@npm:^4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/eslint-plugin@npm:4.6.1" + dependencies: + "@typescript-eslint/experimental-utils": 4.6.1 + "@typescript-eslint/scope-manager": 4.6.1 + debug: ^4.1.1 + functional-red-black-tree: ^1.0.1 + regexpp: ^3.0.0 + semver: ^7.3.2 + tsutils: ^3.17.1 + peerDependencies: + "@typescript-eslint/parser": ^4.0.0 + eslint: ^5.0.0 || ^6.0.0 || ^7.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: fc78ea831ff4d9b22718dc901905beaced2d86545d974f39388aa9272b49291c3f619435cbd23950bebeec2449c6cd3fb0a27339d71b8f290fc0cd3a52904956 + languageName: node + linkType: hard + +"@typescript-eslint/experimental-utils@npm:4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/experimental-utils@npm:4.6.1" + dependencies: + "@types/json-schema": ^7.0.3 + "@typescript-eslint/scope-manager": 4.6.1 + "@typescript-eslint/types": 4.6.1 + "@typescript-eslint/typescript-estree": 4.6.1 + eslint-scope: ^5.0.0 + eslint-utils: ^2.0.0 + peerDependencies: + eslint: "*" + checksum: d3db49afd5f8ca219d36bbc29ef590c09ecafbba4ec0490c5d55fb7538e8e24ba3db1afcb67a940e41d82b8a32aae21c4bfac21f96f24c596410ad702d0be730 + languageName: node + linkType: hard + "@typescript-eslint/experimental-utils@npm:^2.5.0": version: 2.19.0 resolution: "@typescript-eslint/experimental-utils@npm:2.19.0" @@ -3982,6 +4054,40 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/parser@npm:^4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/parser@npm:4.6.1" + dependencies: + "@typescript-eslint/scope-manager": 4.6.1 + "@typescript-eslint/types": 4.6.1 + "@typescript-eslint/typescript-estree": 4.6.1 + debug: ^4.1.1 + peerDependencies: + eslint: ^5.0.0 || ^6.0.0 || ^7.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: e5e363abecdcc3b65e3ea9ff00c951383a0b2a5e4dd8393b4a23e146db7213c35c8d01009962230759d708f021b185b59c47294e9e3829c8ce32404818ba486e + languageName: node + linkType: hard + +"@typescript-eslint/scope-manager@npm:4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/scope-manager@npm:4.6.1" + dependencies: + "@typescript-eslint/types": 4.6.1 + "@typescript-eslint/visitor-keys": 4.6.1 + checksum: 84720a310794974f40781b10c1f437cb756ce8527c3047159c0419dcc7e5478258d13950f9d58a29b6e067537b37aa73e0487169709dacc5b5de3627d2115cac + languageName: node + linkType: hard + +"@typescript-eslint/types@npm:4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/types@npm:4.6.1" + checksum: 06ce9de4dd9a813cee36e3167bf4bda95b427bd94517db272602b0e3e08113562f315b80cfb83549d22c8c50331bd25357dae41756e54ea095d9d80e2b57b54e + languageName: node + linkType: hard + "@typescript-eslint/typescript-estree@npm:2.19.0": version: 2.19.0 resolution: "@typescript-eslint/typescript-estree@npm:2.19.0" @@ -4002,6 +4108,35 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/typescript-estree@npm:4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/typescript-estree@npm:4.6.1" + dependencies: + "@typescript-eslint/types": 4.6.1 + "@typescript-eslint/visitor-keys": 4.6.1 + debug: ^4.1.1 + globby: ^11.0.1 + is-glob: ^4.0.1 + lodash: ^4.17.15 + semver: ^7.3.2 + tsutils: ^3.17.1 + peerDependenciesMeta: + typescript: + optional: true + checksum: 68765299b57eaf14273b22278bdaf40aa11d22605367fadc5cb33266c6947ed8409284586546ff8353482cbdb826a99cf11e6dd8a9c3bf224dd15619676da7aa + languageName: node + linkType: hard + +"@typescript-eslint/visitor-keys@npm:4.6.1": + version: 4.6.1 + resolution: "@typescript-eslint/visitor-keys@npm:4.6.1" + dependencies: + "@typescript-eslint/types": 4.6.1 + eslint-visitor-keys: ^2.0.0 + checksum: 802a53900cee72fd53db5d0f24bfa6fa8078a998ca202af1baeff63a6939128ca98309f33fbe027042332e120768661d4892e16d045fb2590f08c924634ffb6a + languageName: node + linkType: hard + "JSONStream@npm:^1.0.3": version: 1.3.5 resolution: "JSONStream@npm:1.3.5" @@ -4703,6 +4838,7 @@ __metadata: "@babel/plugin-transform-runtime": ^7.12.0 "@babel/preset-env": ^7.12.0 "@babel/preset-flow": ^7.10.4 + "@babel/preset-typescript": ^7.12.1 "@babel/register": ^7.12.0 "@babel/runtime": ^7.12.0 "@rollup/plugin-babel": ^5.2.0 @@ -4710,6 +4846,8 @@ __metadata: "@rollup/plugin-json": ^4.1.0 "@rollup/plugin-node-resolve": ^9.0.0 "@rollup/plugin-replace": ^2.3.3 + "@typescript-eslint/eslint-plugin": ^4.6.1 + "@typescript-eslint/parser": ^4.6.1 babel-plugin-transform-charcodes: ^0.2.0 chalk: ^2.4.2 charcodes: ^0.2.0 @@ -4737,7 +4875,7 @@ __metadata: rollup-plugin-terser: ^7.0.0 test262-stream: ^1.3.0 through2: ^2.0.0 - typescript: ^3.6.3 + typescript: ^4.0.5 dependenciesMeta: core-js: built: false @@ -6581,7 +6719,7 @@ __metadata: languageName: node linkType: hard -"eslint-utils@npm:^2.1.0": +"eslint-utils@npm:^2.0.0, eslint-utils@npm:^2.1.0": version: 2.1.0 resolution: "eslint-utils@npm:2.1.0" dependencies: @@ -6597,6 +6735,13 @@ __metadata: languageName: node linkType: hard +"eslint-visitor-keys@npm:^2.0.0": + version: 2.0.0 + resolution: "eslint-visitor-keys@npm:2.0.0" + checksum: 429dabdcab3c1cf5e65d44843afc513398d4ee32a37f93edc93bb5ba59a12b78fa67d87ff23c752c170b5e4f9085050f45b3c036cdfb23d40a724f2614048140 + languageName: node + linkType: hard + "eslint@npm:^7.5.0": version: 7.5.0 resolution: "eslint@npm:7.5.0" @@ -6958,16 +7103,17 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:^3.0.3": - version: 3.1.1 - resolution: "fast-glob@npm:3.1.1" +"fast-glob@npm:^3.0.3, fast-glob@npm:^3.1.1": + version: 3.2.4 + resolution: "fast-glob@npm:3.2.4" dependencies: "@nodelib/fs.stat": ^2.0.2 "@nodelib/fs.walk": ^1.2.3 glob-parent: ^5.1.0 merge2: ^1.3.0 micromatch: ^4.0.2 - checksum: 74bc2df1287f12a1e69127c9ba3599d622c662b617431de1598e1d80f4bd427f553e76e25651d48a6b21615cdd921b4c32f8b1e74590d890e4c8cd6ef912df38 + picomatch: ^2.2.1 + checksum: 18f9eca898bc3be71b717cb59cb424e937bb9f5629449ba4e93e498dca9db921a9fd3cbdc3389d3f94aec3074bbe2ff6a74f779627a93e81ba0262b795ec44e4 languageName: node linkType: hard @@ -7559,6 +7705,20 @@ fsevents@^1.2.7: languageName: node linkType: hard +"globby@npm:^11.0.1": + version: 11.0.1 + resolution: "globby@npm:11.0.1" + dependencies: + array-union: ^2.1.0 + dir-glob: ^3.0.1 + fast-glob: ^3.1.1 + ignore: ^5.1.4 + merge2: ^1.3.0 + slash: ^3.0.0 + checksum: e7239e9e468c3692aec31dc97b5efc13dd21edf38820baeda98118ade39f475c4ff9e7610859eb4a3c75277ca2616e371265fec3c626aba5db4335bc41c59ac7 + languageName: node + linkType: hard + "glogg@npm:^1.0.0": version: 1.0.2 resolution: "glogg@npm:1.0.2" @@ -7923,10 +8083,10 @@ fsevents@^1.2.7: languageName: node linkType: hard -"ignore@npm:^5.1.1": - version: 5.1.4 - resolution: "ignore@npm:5.1.4" - checksum: 215721af976442f3836b5baa3c1e212c946aadb15609940f851d058b283c84950659bceb245faee7f5476a50d32999af4cdccb7f1c1e4446a728133584938e6c +"ignore@npm:^5.1.1, ignore@npm:^5.1.4": + version: 5.1.8 + resolution: "ignore@npm:5.1.8" + checksum: b08e3d5b5d94eca13475f29a5d47d221060e9cdd7e38d7647088e29d90130669a970fecbc4cdb41b8fa295c6673740c729d3dc05dadc381f593efb42282cbf9f languageName: node linkType: hard @@ -11289,7 +11449,7 @@ fsevents@^1.2.7: languageName: node linkType: hard -"regexpp@npm:^3.1.0": +"regexpp@npm:^3.0.0, regexpp@npm:^3.1.0": version: 3.1.0 resolution: "regexpp@npm:3.1.0" checksum: 69d0ce6b449cf35d3732d6341a1e70850360ffc619f8eef10629871c462e614853fffb80d3f00fc17cd0bb5b8f34b0cde5be4b434e72c0eb3fbba2360c8b5ac4 @@ -12893,23 +13053,23 @@ fsevents@^1.2.7: languageName: node linkType: hard -typescript@^3.6.3: - version: 3.9.7 - resolution: "typescript@npm:3.9.7" +typescript@^4.0.5: + version: 4.0.5 + resolution: "typescript@npm:4.0.5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10848a9c35fd8c70a8792b8bd9485317534bcd58768793d3b7d9c7486e9fd30cf345f83fa2a324e0bf6088bc8a4d8d061d58fda38b18c2ff187cf01fbbff6267 + checksum: ce94d4bbb914cc9d6fbd42e1476ab18c3292b262b8ba7ba76cd167a858545207a604e75bf1efbb75b8654c8f85deaa19795c3ef00098d7612855139b4ecc0240 languageName: node linkType: hard -"typescript@patch:typescript@^3.6.3#builtin": - version: 3.9.7 - resolution: "typescript@patch:typescript@npm%3A3.9.7#builtin::version=3.9.7&hash=5bf698" +"typescript@patch:typescript@^4.0.5#builtin": + version: 4.0.5 + resolution: "typescript@patch:typescript@npm%3A4.0.5#builtin::version=4.0.5&hash=5bf698" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: f0d3d9c987860c7c458229ab6dd7e3d322405db36b70abccba610b5efd9f9451e4e67a3fc7983c0d3741033c1f1a8d7aa859a1510caa8f20fad762fc39648bfa + checksum: d4be0bd2a2050b2d7b132cb2a40329178f181543e9d2ac6d1f06babd9f047208558a736a7effdeb28759ae2e815f070b61d10ee2f02cc93a6221a1490f21ffce languageName: node linkType: hard