@babel/core
Advanced tools
Comparing version 7.20.12 to 7.21.0
@@ -63,8 +63,8 @@ "use strict"; | ||
const debug = _debug()("babel:config:loading:files:configuration"); | ||
const ROOT_CONFIG_FILENAMES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json"]; | ||
const ROOT_CONFIG_FILENAMES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json", "babel.config.cts"]; | ||
exports.ROOT_CONFIG_FILENAMES = ROOT_CONFIG_FILENAMES; | ||
const RELATIVE_CONFIG_FILENAMES = [".babelrc", ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", ".babelrc.json"]; | ||
const RELATIVE_CONFIG_FILENAMES = [".babelrc", ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", ".babelrc.json", ".babelrc.cts"]; | ||
const BABELIGNORE_FILENAME = ".babelignore"; | ||
const LOADING_CONFIGS = new Set(); | ||
const readConfigJS = (0, _caching.makeStrongCache)(function* readConfigJS(filepath, cache) { | ||
const readConfigCode = (0, _caching.makeStrongCache)(function* readConfigCode(filepath, cache) { | ||
if (!_fs().existsSync(filepath)) { | ||
@@ -229,6 +229,14 @@ cache.never(); | ||
const ext = _path().extname(filepath); | ||
return ext === ".js" || ext === ".cjs" || ext === ".mjs" ? readConfigJS(filepath, { | ||
envName, | ||
caller | ||
}) : readConfigJSON5(filepath); | ||
switch (ext) { | ||
case ".js": | ||
case ".cjs": | ||
case ".mjs": | ||
case ".cts": | ||
return readConfigCode(filepath, { | ||
envName, | ||
caller | ||
}); | ||
default: | ||
return readConfigJSON5(filepath); | ||
} | ||
} | ||
@@ -235,0 +243,0 @@ function* resolveShowConfigPath(dirname) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = loadCjsOrMjsDefault; | ||
exports.default = loadCodeDefault; | ||
exports.supportsESM = void 0; | ||
@@ -40,2 +40,3 @@ var _async = require("../../gensync-utils/async"); | ||
var _configError = require("../../errors/config-error"); | ||
var _transformFile = require("../../transform-file"); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
@@ -49,7 +50,11 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
exports.supportsESM = supportsESM; | ||
function* loadCjsOrMjsDefault(filepath, asyncError, fallbackToTranspiledModule = false) { | ||
switch (guessJSModuleType(filepath)) { | ||
case "cjs": | ||
function* loadCodeDefault(filepath, asyncError, fallbackToTranspiledModule = false) { | ||
switch (_path().extname(filepath)) { | ||
case ".cjs": | ||
return loadCjsDefault(filepath, fallbackToTranspiledModule); | ||
case "unknown": | ||
case ".mjs": | ||
break; | ||
case ".cts": | ||
return loadCtsDefault(filepath); | ||
default: | ||
try { | ||
@@ -60,18 +65,45 @@ return loadCjsDefault(filepath, fallbackToTranspiledModule); | ||
} | ||
case "mjs": | ||
if (yield* (0, _async.isAsync)()) { | ||
return yield* (0, _async.waitFor)(loadMjsDefault(filepath)); | ||
} | ||
throw new _configError.default(asyncError, filepath); | ||
} | ||
if (yield* (0, _async.isAsync)()) { | ||
return yield* (0, _async.waitFor)(loadMjsDefault(filepath)); | ||
} | ||
throw new _configError.default(asyncError, filepath); | ||
} | ||
function guessJSModuleType(filename) { | ||
switch (_path().extname(filename)) { | ||
case ".cjs": | ||
return "cjs"; | ||
case ".mjs": | ||
return "mjs"; | ||
default: | ||
return "unknown"; | ||
function loadCtsDefault(filepath) { | ||
const ext = ".cts"; | ||
const hasTsSupport = !!(require.extensions[".ts"] || require.extensions[".cts"] || require.extensions[".mts"]); | ||
let handler; | ||
if (!hasTsSupport) { | ||
const opts = { | ||
babelrc: false, | ||
configFile: false, | ||
sourceType: "script", | ||
sourceMaps: "inline", | ||
presets: [[getTSPreset(filepath), Object.assign({ | ||
disallowAmbiguousJSXLike: true, | ||
allExtensions: true, | ||
onlyRemoveTypeImports: true, | ||
optimizeConstEnums: true | ||
}, { | ||
allowDeclareFields: true | ||
})]] | ||
}; | ||
handler = function (m, filename) { | ||
if (handler && filename.endsWith(ext)) { | ||
return m._compile((0, _transformFile.transformFileSync)(filename, Object.assign({}, opts, { | ||
filename | ||
})).code, filename); | ||
} | ||
return require.extensions[".js"](m, filename); | ||
}; | ||
require.extensions[ext] = handler; | ||
} | ||
try { | ||
return (0, _rewriteStackTrace.endHiddenCallStack)(require)(filepath); | ||
} finally { | ||
if (!hasTsSupport) { | ||
if (require.extensions[ext] === handler) delete require.extensions[ext]; | ||
handler = undefined; | ||
} | ||
} | ||
} | ||
@@ -88,3 +120,3 @@ function loadCjsDefault(filepath, fallbackToTranspiledModule) { | ||
if (!import_) { | ||
throw new _configError.default("Internal error: Native ECMAScript modules aren't supported" + " by this platform.\n", filepath); | ||
throw new _configError.default("Internal error: Native ECMAScript modules aren't supported by this platform.\n", filepath); | ||
} | ||
@@ -96,4 +128,23 @@ const module = yield (0, _rewriteStackTrace.endHiddenCallStack)(import_)((0, _url().pathToFileURL)(filepath)); | ||
} | ||
function getTSPreset(filepath) { | ||
try { | ||
return require("@babel/preset-typescript"); | ||
} catch (error) { | ||
if (error.code !== "MODULE_NOT_FOUND") throw error; | ||
let message = "You appear to be using a .cts file as Babel configuration, but the `@babel/preset-typescript` package was not found: please install it!"; | ||
if (process.versions.pnp) { | ||
message += ` | ||
If you are using Yarn Plug'n'Play, you may also need to add the following configuration to your .yarnrc.yml file: | ||
packageExtensions: | ||
\t"@babel/core@*": | ||
\t\tpeerDependencies: | ||
\t\t\t"@babel/preset-typescript": "*" | ||
`; | ||
} | ||
throw new _configError.default(message, filepath); | ||
} | ||
} | ||
0 && 0; | ||
//# sourceMappingURL=module-types.js.map |
@@ -73,3 +73,3 @@ "use strict"; | ||
} | ||
const knownAssumptions = ["arrayLikeIsIterable", "constantReexports", "constantSuper", "enumerableModuleMeta", "ignoreFunctionLength", "ignoreToPrimitiveHint", "iterableIsArray", "mutableTemplateObject", "noClassCalls", "noDocumentAll", "noIncompleteNsImportDetection", "noNewArrows", "objectRestNoSymbols", "privateFieldsAsProperties", "pureGetters", "setClassMethods", "setComputedProperties", "setPublicClassFields", "setSpreadProperties", "skipForOfIteratorClosing", "superIsCallableConstructor"]; | ||
const knownAssumptions = ["arrayLikeIsIterable", "constantReexports", "constantSuper", "enumerableModuleMeta", "ignoreFunctionLength", "ignoreToPrimitiveHint", "iterableIsArray", "mutableTemplateObject", "noClassCalls", "noDocumentAll", "noIncompleteNsImportDetection", "noNewArrows", "objectRestNoSymbols", "privateFieldsAsSymbols", "privateFieldsAsProperties", "pureGetters", "setClassMethods", "setComputedProperties", "setPublicClassFields", "setSpreadProperties", "skipForOfIteratorClosing", "superIsCallableConstructor"]; | ||
const assumptionsNames = new Set(knownAssumptions); | ||
@@ -76,0 +76,0 @@ exports.assumptionsNames = assumptionsNames; |
@@ -12,3 +12,3 @@ "use strict"; | ||
(0, _rewriteStackTrace.expectedError)(this); | ||
if (filename) (0, _rewriteStackTrace.injcectVirtualStackFrame)(this, filename); | ||
if (filename) (0, _rewriteStackTrace.injectVirtualStackFrame)(this, filename); | ||
} | ||
@@ -15,0 +15,0 @@ } |
@@ -9,7 +9,7 @@ "use strict"; | ||
exports.expectedError = expectedError; | ||
exports.injcectVirtualStackFrame = injcectVirtualStackFrame; | ||
exports.injectVirtualStackFrame = injectVirtualStackFrame; | ||
const ErrorToString = Function.call.bind(Error.prototype.toString); | ||
const SUPPORTED = !!Error.captureStackTrace; | ||
const START_HIDNG = "startHiding - secret - don't use this - v1"; | ||
const STOP_HIDNG = "stopHiding - secret - don't use this - v1"; | ||
const START_HIDING = "startHiding - secret - don't use this - v1"; | ||
const STOP_HIDING = "stopHiding - secret - don't use this - v1"; | ||
const expectedErrors = new WeakSet(); | ||
@@ -31,3 +31,3 @@ const virtualFrames = new WeakMap(); | ||
} | ||
function injcectVirtualStackFrame(error, filename) { | ||
function injectVirtualStackFrame(error, filename) { | ||
if (!SUPPORTED) return; | ||
@@ -50,3 +50,3 @@ let frames = virtualFrames.get(error); | ||
}, "name", { | ||
value: STOP_HIDNG | ||
value: STOP_HIDING | ||
}); | ||
@@ -59,3 +59,3 @@ } | ||
}, "name", { | ||
value: START_HIDNG | ||
value: START_HIDING | ||
}); | ||
@@ -76,5 +76,5 @@ } | ||
const name = trace[i].getFunctionName(); | ||
if (name === START_HIDNG) { | ||
if (name === START_HIDING) { | ||
status = "hiding"; | ||
} else if (name === STOP_HIDNG) { | ||
} else if (name === STOP_HIDING) { | ||
if (status === "hiding") { | ||
@@ -81,0 +81,0 @@ status = "showing"; |
@@ -227,3 +227,11 @@ "use strict"; | ||
var _parse = require("./parse"); | ||
const version = "7.20.12"; | ||
function _module() { | ||
const data = require("module"); | ||
_module = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var thisFile = require("./index"); | ||
const version = "7.21.0"; | ||
exports.version = version; | ||
@@ -241,4 +249,5 @@ const DEFAULT_EXTENSIONS = Object.freeze([".js", ".jsx", ".es6", ".es", ".mjs", ".cjs"]); | ||
} | ||
; | ||
0 && (exports.types = exports.traverse = exports.tokTypes = exports.template = 0); | ||
//# sourceMappingURL=index.js.map |
@@ -32,2 +32,3 @@ "use strict"; | ||
} = opts; | ||
generatorOpts.inputSourceMap = inputMap == null ? void 0 : inputMap.toObject(); | ||
const results = []; | ||
@@ -60,7 +61,11 @@ for (const plugins of pluginPasses) { | ||
} = result; | ||
if (outputMap) { | ||
if (inputMap) { | ||
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap, generatorOpts.sourceFileName); | ||
} else { | ||
outputMap = result.map; | ||
if (result.__mergedMap) { | ||
outputMap = Object.assign({}, result.map); | ||
} else { | ||
if (outputMap) { | ||
if (inputMap) { | ||
outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap, generatorOpts.sourceFileName); | ||
} else { | ||
outputMap = result.map; | ||
} | ||
} | ||
@@ -67,0 +72,0 @@ } |
@@ -50,3 +50,2 @@ "use strict"; | ||
const debug = _debug()("babel:transform:file"); | ||
const LARGE_INPUT_SOURCEMAP_THRESHOLD = 3000000; | ||
const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/; | ||
@@ -88,8 +87,4 @@ const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/; | ||
const match = EXTERNAL_SOURCEMAP_REGEX.exec(lastComment); | ||
const inputMapContent = _fs().readFileSync(_path().resolve(_path().dirname(options.filename), match[1])); | ||
if (inputMapContent.length > LARGE_INPUT_SOURCEMAP_THRESHOLD) { | ||
debug("skip merging input map > 1 MB"); | ||
} else { | ||
inputMap = _convertSourceMap().fromJSON(inputMapContent); | ||
} | ||
const inputMapContent = _fs().readFileSync(_path().resolve(_path().dirname(options.filename), match[1]), "utf8"); | ||
inputMap = _convertSourceMap().fromJSON(inputMapContent); | ||
} catch (err) { | ||
@@ -96,0 +91,0 @@ debug("discarding unknown file input sourcemap", err); |
@@ -13,2 +13,3 @@ "use strict"; | ||
cloned = new Array(value.length); | ||
cache.set(value, cloned); | ||
for (let i = 0; i < value.length; i++) { | ||
@@ -19,2 +20,3 @@ cloned[i] = typeof value[i] !== "object" ? value[i] : deepClone(value[i], cache); | ||
cloned = {}; | ||
cache.set(value, cloned); | ||
const keys = Object.keys(value); | ||
@@ -26,3 +28,2 @@ for (let i = 0; i < keys.length; i++) { | ||
} | ||
cache.set(value, cloned); | ||
return cloned; | ||
@@ -29,0 +30,0 @@ } |
{ | ||
"name": "@babel/core", | ||
"version": "7.20.12", | ||
"version": "7.21.0", | ||
"description": "Babel compiler core.", | ||
@@ -49,12 +49,12 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@ampproject/remapping": "^2.1.0", | ||
"@ampproject/remapping": "^2.2.0", | ||
"@babel/code-frame": "^7.18.6", | ||
"@babel/generator": "^7.20.7", | ||
"@babel/generator": "^7.21.0", | ||
"@babel/helper-compilation-targets": "^7.20.7", | ||
"@babel/helper-module-transforms": "^7.20.11", | ||
"@babel/helpers": "^7.20.7", | ||
"@babel/parser": "^7.20.7", | ||
"@babel/helper-module-transforms": "^7.21.0", | ||
"@babel/helpers": "^7.21.0", | ||
"@babel/parser": "^7.21.0", | ||
"@babel/template": "^7.20.7", | ||
"@babel/traverse": "^7.20.12", | ||
"@babel/types": "^7.20.7", | ||
"@babel/traverse": "^7.21.0", | ||
"@babel/types": "^7.21.0", | ||
"convert-source-map": "^1.7.0", | ||
@@ -67,8 +67,8 @@ "debug": "^4.1.0", | ||
"devDependencies": { | ||
"@babel/helper-transform-fixture-test-runner": "^7.19.4", | ||
"@babel/helper-transform-fixture-test-runner": "^7.20.14", | ||
"@babel/plugin-syntax-flow": "^7.18.6", | ||
"@babel/plugin-transform-flow-strip-types": "^7.19.0", | ||
"@babel/plugin-transform-flow-strip-types": "^7.21.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.20.11", | ||
"@babel/preset-env": "^7.20.2", | ||
"@jridgewell/trace-mapping": "^0.3.8", | ||
"@jridgewell/trace-mapping": "^0.3.17", | ||
"@types/convert-source-map": "^1.5.1", | ||
@@ -79,5 +79,6 @@ "@types/debug": "^4.1.0", | ||
"@types/semver": "^5.4.0", | ||
"rimraf": "^3.0.0" | ||
"rimraf": "^3.0.0", | ||
"ts-node": "^10.9.1" | ||
}, | ||
"type": "commonjs" | ||
} |
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
944581
8672
13
16
Updated@ampproject/remapping@^2.2.0
Updated@babel/generator@^7.21.0
Updated@babel/helpers@^7.21.0
Updated@babel/parser@^7.21.0
Updated@babel/traverse@^7.21.0
Updated@babel/types@^7.21.0