Commit a2e8cafb authored by patri's avatar patri
Browse files

Test New PC

parent e65a993d
...@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.default = generateCode; exports.default = generateCode;
function _convertSourceMap() { function _convertSourceMap() {
const data = _interopRequireDefault(require("convert-source-map")); const data = require("convert-source-map");
_convertSourceMap = function () { _convertSourceMap = function () {
return data; return data;
...@@ -16,7 +16,7 @@ function _convertSourceMap() { ...@@ -16,7 +16,7 @@ function _convertSourceMap() {
} }
function _generator() { function _generator() {
const data = _interopRequireDefault(require("@babel/generator")); const data = require("@babel/generator");
_generator = function () { _generator = function () {
return data; return data;
...@@ -25,9 +25,7 @@ function _generator() { ...@@ -25,9 +25,7 @@ function _generator() {
return data; return data;
} }
var _mergeMap = _interopRequireDefault(require("./merge-map")); var _mergeMap = require("./merge-map");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function generateCode(pluginPasses, file) { function generateCode(pluginPasses, file) {
const { const {
...@@ -75,7 +73,7 @@ function generateCode(pluginPasses, file) { ...@@ -75,7 +73,7 @@ function generateCode(pluginPasses, file) {
} }
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") { if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {
outputCode += "\n" + _convertSourceMap().default.fromObject(outputMap).toComment(); outputCode += "\n" + _convertSourceMap().fromObject(outputMap).toComment();
} }
if (opts.sourceMaps === "inline") { if (opts.sourceMaps === "inline") {
......
...@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.default = mergeSourceMap; exports.default = mergeSourceMap;
function _sourceMap() { function _sourceMap() {
const data = _interopRequireDefault(require("source-map")); const data = require("source-map");
_sourceMap = function () { _sourceMap = function () {
return data; return data;
...@@ -15,18 +15,14 @@ function _sourceMap() { ...@@ -15,18 +15,14 @@ function _sourceMap() {
return data; return data;
} }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function mergeSourceMap(inputMap, map) { function mergeSourceMap(inputMap, map) {
const input = buildMappingData(inputMap); const input = buildMappingData(inputMap);
const output = buildMappingData(map); const output = buildMappingData(map);
const mergedGenerator = new (_sourceMap().default.SourceMapGenerator)(); const mergedGenerator = new (_sourceMap().SourceMapGenerator)();
for (const _ref of input.sources) {
const {
source
} = _ref;
for (const {
source
} of input.sources) {
if (typeof source.content === "string") { if (typeof source.content === "string") {
mergedGenerator.setSourceContent(source.path, source.content); mergedGenerator.setSourceContent(source.path, source.content);
} }
...@@ -95,11 +91,9 @@ function makeMappingKey(item) { ...@@ -95,11 +91,9 @@ function makeMappingKey(item) {
function eachOverlappingGeneratedOutputRange(outputFile, inputGeneratedRange, callback) { function eachOverlappingGeneratedOutputRange(outputFile, inputGeneratedRange, callback) {
const overlappingOriginal = filterApplicableOriginalRanges(outputFile, inputGeneratedRange); const overlappingOriginal = filterApplicableOriginalRanges(outputFile, inputGeneratedRange);
for (const _ref2 of overlappingOriginal) { for (const {
const { generated
generated } of overlappingOriginal) {
} = _ref2;
for (const item of generated) { for (const item of generated) {
callback(item); callback(item);
} }
...@@ -125,18 +119,14 @@ function filterApplicableOriginalRanges({ ...@@ -125,18 +119,14 @@ function filterApplicableOriginalRanges({
} }
function eachInputGeneratedRange(map, callback) { function eachInputGeneratedRange(map, callback) {
for (const _ref3 of map.sources) { for (const {
const { source,
source, mappings
mappings } of map.sources) {
} = _ref3; for (const {
original,
for (const _ref4 of mappings) { generated
const { } of mappings) {
original,
generated
} = _ref4;
for (const item of generated) { for (const item of generated) {
callback(item, original, source); callback(item, original, source);
} }
...@@ -145,7 +135,7 @@ function eachInputGeneratedRange(map, callback) { ...@@ -145,7 +135,7 @@ function eachInputGeneratedRange(map, callback) {
} }
function buildMappingData(map) { function buildMappingData(map) {
const consumer = new (_sourceMap().default.SourceMapConsumer)(Object.assign({}, map, { const consumer = new (_sourceMap().SourceMapConsumer)(Object.assign({}, map, {
sourceRoot: null sourceRoot: null
})); }));
const sources = new Map(); const sources = new Map();
...@@ -201,7 +191,7 @@ function buildMappingData(map) { ...@@ -201,7 +191,7 @@ function buildMappingData(map) {
columnEnd: item.lastColumn + 1 columnEnd: item.lastColumn + 1
})) }))
}); });
}, null, _sourceMap().default.SourceMapConsumer.ORIGINAL_ORDER); }, null, _sourceMap().SourceMapConsumer.ORIGINAL_ORDER);
return { return {
file: map.file, file: map.file,
sourceRoot: map.sourceRoot, sourceRoot: map.sourceRoot,
......
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.runAsync = runAsync; exports.run = run;
exports.runSync = runSync;
function _traverse() { function _traverse() {
const data = _interopRequireDefault(require("@babel/traverse")); const data = require("@babel/traverse");
_traverse = function () { _traverse = function () {
return data; return data;
...@@ -16,40 +15,26 @@ function _traverse() { ...@@ -16,40 +15,26 @@ function _traverse() {
return data; return data;
} }
var _pluginPass = _interopRequireDefault(require("./plugin-pass")); var _pluginPass = require("./plugin-pass");
var _blockHoistPlugin = _interopRequireDefault(require("./block-hoist-plugin")); var _blockHoistPlugin = require("./block-hoist-plugin");
var _normalizeOpts = _interopRequireDefault(require("./normalize-opts")); var _normalizeOpts = require("./normalize-opts");
var _normalizeFile = _interopRequireDefault(require("./normalize-file")); var _normalizeFile = require("./normalize-file");
var _generate = _interopRequireDefault(require("./file/generate")); var _generate = require("./file/generate");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function* run(config, code, ast) {
const file = yield* (0, _normalizeFile.default)(config.passes, (0, _normalizeOpts.default)(config), code, ast);
function runAsync(config, code, ast, callback) {
let result;
try {
result = runSync(config, code, ast);
} catch (err) {
return callback(err);
}
return callback(null, result);
}
function runSync(config, code, ast) {
const file = (0, _normalizeFile.default)(config.passes, (0, _normalizeOpts.default)(config), code, ast);
const opts = file.opts; const opts = file.opts;
try { try {
transformFile(file, config.passes); yield* transformFile(file, config.passes);
} catch (e) { } catch (e) {
var _opts$filename; var _opts$filename;
e.message = `${(_opts$filename = opts.filename) !== null && _opts$filename !== void 0 ? _opts$filename : "unknown"}: ${e.message}`; e.message = `${(_opts$filename = opts.filename) != null ? _opts$filename : "unknown"}: ${e.message}`;
if (!e.code) { if (!e.code) {
e.code = "BABEL_TRANSFORM_ERROR"; e.code = "BABEL_TRANSFORM_ERROR";
...@@ -70,7 +55,7 @@ function runSync(config, code, ast) { ...@@ -70,7 +55,7 @@ function runSync(config, code, ast) {
} catch (e) { } catch (e) {
var _opts$filename2; var _opts$filename2;
e.message = `${(_opts$filename2 = opts.filename) !== null && _opts$filename2 !== void 0 ? _opts$filename2 : "unknown"}: ${e.message}`; e.message = `${(_opts$filename2 = opts.filename) != null ? _opts$filename2 : "unknown"}: ${e.message}`;
if (!e.code) { if (!e.code) {
e.code = "BABEL_GENERATE_ERROR"; e.code = "BABEL_GENERATE_ERROR";
...@@ -89,7 +74,7 @@ function runSync(config, code, ast) { ...@@ -89,7 +74,7 @@ function runSync(config, code, ast) {
}; };
} }
function transformFile(file, pluginPasses) { function* transformFile(file, pluginPasses) {
for (const pluginPairs of pluginPasses) { for (const pluginPairs of pluginPasses) {
const passPairs = []; const passPairs = [];
const passes = []; const passes = [];
...@@ -107,6 +92,7 @@ function transformFile(file, pluginPasses) { ...@@ -107,6 +92,7 @@ function transformFile(file, pluginPasses) {
if (fn) { if (fn) {
const result = fn.call(pass, file); const result = fn.call(pass, file);
yield* [];
if (isThenable(result)) { if (isThenable(result)) {
throw new Error(`You appear to be using an plugin with an async .pre, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); throw new Error(`You appear to be using an plugin with an async .pre, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
...@@ -123,6 +109,7 @@ function transformFile(file, pluginPasses) { ...@@ -123,6 +109,7 @@ function transformFile(file, pluginPasses) {
if (fn) { if (fn) {
const result = fn.call(pass, file); const result = fn.call(pass, file);
yield* [];
if (isThenable(result)) { if (isThenable(result)) {
throw new Error(`You appear to be using an plugin with an async .post, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); throw new Error(`You appear to be using an plugin with an async .post, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
......
...@@ -5,30 +5,30 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,30 +5,30 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = normalizeFile; exports.default = normalizeFile;
function _path() { function _fs() {
const data = _interopRequireDefault(require("path")); const data = require("fs");
_path = function () { _fs = function () {
return data; return data;
}; };
return data; return data;
} }
function _debug() { function _path() {
const data = _interopRequireDefault(require("debug")); const data = require("path");
_debug = function () { _path = function () {
return data; return data;
}; };
return data; return data;
} }
function _cloneDeep() { function _debug() {
const data = _interopRequireDefault(require("lodash/cloneDeep")); const data = require("debug");
_cloneDeep = function () { _debug = function () {
return data; return data;
}; };
...@@ -36,7 +36,7 @@ function _cloneDeep() { ...@@ -36,7 +36,7 @@ function _cloneDeep() {
} }
function t() { function t() {
const data = _interopRequireWildcard(require("@babel/types")); const data = require("@babel/types");
t = function () { t = function () {
return data; return data;
...@@ -46,7 +46,7 @@ function t() { ...@@ -46,7 +46,7 @@ function t() {
} }
function _convertSourceMap() { function _convertSourceMap() {
const data = _interopRequireDefault(require("convert-source-map")); const data = require("convert-source-map");
_convertSourceMap = function () { _convertSourceMap = function () {
return data; return data;
...@@ -55,39 +55,17 @@ function _convertSourceMap() { ...@@ -55,39 +55,17 @@ function _convertSourceMap() {
return data; return data;
} }
function _parser() { var _file = require("./file/file");
const data = require("@babel/parser");
_parser = function () {
return data;
};
return data;
}
function _codeFrame() {
const data = require("@babel/code-frame");
_codeFrame = function () {
return data;
};
return data;
}
var _file = _interopRequireDefault(require("./file/file"));
var _missingPluginHelper = _interopRequireDefault(require("./util/missing-plugin-helper"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } var _parser = require("../parser");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var _cloneDeep = require("./util/clone-deep");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const debug = _debug()("babel:transform:file");
const debug = (0, _debug().default)("babel:transform:file"); const LARGE_INPUT_SOURCEMAP_THRESHOLD = 1000000;
function normalizeFile(pluginPasses, options, code, ast) { function* normalizeFile(pluginPasses, options, code, ast) {
code = `${code || ""}`; code = `${code || ""}`;
if (ast) { if (ast) {
...@@ -97,16 +75,18 @@ function normalizeFile(pluginPasses, options, code, ast) { ...@@ -97,16 +75,18 @@ function normalizeFile(pluginPasses, options, code, ast) {
throw new Error("AST root must be a Program or File node"); throw new Error("AST root must be a Program or File node");
} }
ast = (0, _cloneDeep().default)(ast); if (options.cloneInputAst) {
ast = (0, _cloneDeep.default)(ast);
}
} else { } else {
ast = parser(pluginPasses, options, code); ast = yield* (0, _parser.default)(pluginPasses, options, code);
} }
let inputMap = null; let inputMap = null;
if (options.inputSourceMap !== false) { if (options.inputSourceMap !== false) {
if (typeof options.inputSourceMap === "object") { if (typeof options.inputSourceMap === "object") {
inputMap = _convertSourceMap().default.fromObject(options.inputSourceMap); inputMap = _convertSourceMap().fromObject(options.inputSourceMap);
} }
if (!inputMap) { if (!inputMap) {
...@@ -114,7 +94,7 @@ function normalizeFile(pluginPasses, options, code, ast) { ...@@ -114,7 +94,7 @@ function normalizeFile(pluginPasses, options, code, ast) {
if (lastComment) { if (lastComment) {
try { try {
inputMap = _convertSourceMap().default.fromComment(lastComment); inputMap = _convertSourceMap().fromComment(lastComment);
} catch (err) { } catch (err) {
debug("discarding unknown inline input sourcemap", err); debug("discarding unknown inline input sourcemap", err);
} }
...@@ -126,7 +106,15 @@ function normalizeFile(pluginPasses, options, code, ast) { ...@@ -126,7 +106,15 @@ function normalizeFile(pluginPasses, options, code, ast) {
if (typeof options.filename === "string" && lastComment) { if (typeof options.filename === "string" && lastComment) {
try { try {
inputMap = _convertSourceMap().default.fromMapFileComment(`//${lastComment}`, _path().default.dirname(options.filename)); 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);
}
} catch (err) { } catch (err) {
debug("discarding unknown file input sourcemap", err); debug("discarding unknown file input sourcemap", err);
} }
...@@ -143,73 +131,8 @@ function normalizeFile(pluginPasses, options, code, ast) { ...@@ -143,73 +131,8 @@ function normalizeFile(pluginPasses, options, code, ast) {
}); });
} }
function parser(pluginPasses, {
parserOpts,
highlightCode = true,
filename = "unknown"
}, code) {
try {
const results = [];
for (const plugins of pluginPasses) {
for (const plugin of plugins) {
const {
parserOverride
} = plugin;
if (parserOverride) {
const ast = parserOverride(code, parserOpts, _parser().parse);
if (ast !== undefined) results.push(ast);
}
}
}
if (results.length === 0) {
return (0, _parser().parse)(code, parserOpts);
} else if (results.length === 1) {
if (typeof results[0].then === "function") {
throw new Error(`You appear to be using an async parser plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
}
return results[0];
}
throw new Error("More than one plugin attempted to override parsing.");
} catch (err) {
if (err.code === "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED") {
err.message += "\nConsider renaming the file to '.mjs', or setting sourceType:module " + "or sourceType:unambiguous in your Babel config for this file.";
}
const {
loc,
missingPlugin
} = err;
if (loc) {
const codeFrame = (0, _codeFrame().codeFrameColumns)(code, {
start: {
line: loc.line,
column: loc.column + 1
}
}, {
highlightCode
});
if (missingPlugin) {
err.message = `${filename}: ` + (0, _missingPluginHelper.default)(missingPlugin[0], loc, codeFrame);
} else {
err.message = `${filename}: ${err.message}\n\n` + codeFrame;
}
err.code = "BABEL_PARSE_ERROR";
}
throw err;
}
}
const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/; const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/;
const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=(?:[^\s'"`]+?)[ \t]*$/; const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/;
function extractCommentsFromList(regex, comments, lastComment) { function extractCommentsFromList(regex, comments, lastComment) {
if (comments) { if (comments) {
......
...@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.default = normalizeOptions; exports.default = normalizeOptions;
function _path() { function _path() {
const data = _interopRequireDefault(require("path")); const data = require("path");
_path = function () { _path = function () {
return data; return data;
...@@ -15,26 +15,23 @@ function _path() { ...@@ -15,26 +15,23 @@ function _path() {
return data; return data;
} }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function normalizeOptions(config) { function normalizeOptions(config) {
const { const {
filename, filename,
cwd, cwd,
filenameRelative = typeof filename === "string" ? _path().default.relative(cwd, filename) : "unknown", filenameRelative = typeof filename === "string" ? _path().relative(cwd, filename) : "unknown",
sourceType = "module", sourceType = "module",
inputSourceMap, inputSourceMap,
sourceMaps = !!inputSourceMap, sourceMaps = !!inputSourceMap,
moduleRoot, sourceRoot = config.options.moduleRoot,
sourceRoot = moduleRoot, sourceFileName = _path().basename(filenameRelative),
sourceFileName = _path().default.basename(filenameRelative),
comments = true, comments = true,
compact = "auto" compact = "auto"
} = config.options; } = config.options;
const opts = config.options; const opts = config.options;
const options = Object.assign({}, opts, { const options = Object.assign({}, opts, {
parserOpts: Object.assign({ parserOpts: Object.assign({
sourceType: _path().default.extname(filenameRelative) === ".mjs" ? "module" : sourceType, sourceType: _path().extname(filenameRelative) === ".mjs" ? "module" : sourceType,
sourceFileName: filename, sourceFileName: filename,
plugins: [] plugins: []
}, opts.parserOpts), }, opts.parserOpts),
......
...@@ -8,6 +8,11 @@ exports.default = void 0; ...@@ -8,6 +8,11 @@ exports.default = void 0;
class PluginPass { class PluginPass {
constructor(file, key, options) { constructor(file, key, options) {
this._map = new Map(); this._map = new Map();
this.key = void 0;
this.file = void 0;
this.opts = void 0;
this.cwd = void 0;
this.filename = void 0;
this.key = key; this.key = key;
this.file = file; this.file = file;
this.opts = options || {}; this.opts = options || {};
...@@ -35,14 +40,15 @@ class PluginPass { ...@@ -35,14 +40,15 @@ class PluginPass {
return this.file.addImport(); return this.file.addImport();
} }
getModuleName() { buildCodeFrameError(node, msg, _Error) {
return this.file.getModuleName(); return this.file.buildCodeFrameError(node, msg, _Error);
}
buildCodeFrameError(node, msg, Error) {
return this.file.buildCodeFrameError(node, msg, Error);
} }
} }
exports.default = PluginPass; exports.default = PluginPass;
\ No newline at end of file {
PluginPass.prototype.getModuleName = function getModuleName() {
return this.file.getModuleName();
};
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = generateMissingPluginMessage;
const pluginNameMap = {
classProperties: {
syntax: {
name: "@babel/plugin-syntax-class-properties",
url: "https://git.io/vb4yQ"
},
transform: {
name: "@babel/plugin-proposal-class-properties",
url: "https://git.io/vb4SL"
}
},
decorators: {
syntax: {
name: "@babel/plugin-syntax-decorators",
url: "https://git.io/vb4y9"
},
transform: {
name: "@babel/plugin-proposal-decorators",
url: "https://git.io/vb4ST"
}
},
doExpressions: {
syntax: {
name: "@babel/plugin-syntax-do-expressions",
url: "https://git.io/vb4yh"
},
transform: {
name: "@babel/plugin-proposal-do-expressions",
url: "https://git.io/vb4S3"
}
},
dynamicImport: {
syntax: {
name: "@babel/plugin-syntax-dynamic-import",
url: "https://git.io/vb4Sv"
}
},
exportDefaultFrom: {
syntax: {
name: "@babel/plugin-syntax-export-default-from",
url: "https://git.io/vb4SO"
},
transform: {
name: "@babel/plugin-proposal-export-default-from",
url: "https://git.io/vb4yH"
}
},
exportNamespaceFrom: {
syntax: {
name: "@babel/plugin-syntax-export-namespace-from",
url: "https://git.io/vb4Sf"
},
transform: {
name: "@babel/plugin-proposal-export-namespace-from",
url: "https://git.io/vb4SG"
}
},
flow: {
syntax: {
name: "@babel/plugin-syntax-flow",
url: "https://git.io/vb4yb"
},
transform: {
name: "@babel/plugin-transform-flow-strip-types",
url: "https://git.io/vb49g"
}
},
functionBind: {
syntax: {
name: "@babel/plugin-syntax-function-bind",
url: "https://git.io/vb4y7"
},
transform: {
name: "@babel/plugin-proposal-function-bind",
url: "https://git.io/vb4St"
}
},
functionSent: {
syntax: {
name: "@babel/plugin-syntax-function-sent",
url: "https://git.io/vb4yN"
},
transform: {
name: "@babel/plugin-proposal-function-sent",
url: "https://git.io/vb4SZ"
}
},
importMeta: {
syntax: {
name: "@babel/plugin-syntax-import-meta",
url: "https://git.io/vbKK6"
}
},
jsx: {
syntax: {
name: "@babel/plugin-syntax-jsx",
url: "https://git.io/vb4yA"
},
transform: {
name: "@babel/plugin-transform-react-jsx",
url: "https://git.io/vb4yd"
}
},
logicalAssignment: {
syntax: {
name: "@babel/plugin-syntax-logical-assignment-operators",
url: "https://git.io/vAlBp"
},
transform: {
name: "@babel/plugin-proposal-logical-assignment-operators",
url: "https://git.io/vAlRe"
}
},
nullishCoalescingOperator: {
syntax: {
name: "@babel/plugin-syntax-nullish-coalescing-operator",
url: "https://git.io/vb4yx"
},
transform: {
name: "@babel/plugin-proposal-nullish-coalescing-operator",
url: "https://git.io/vb4Se"
}
},
numericSeparator: {
syntax: {
name: "@babel/plugin-syntax-numeric-separator",
url: "https://git.io/vb4Sq"
},
transform: {
name: "@babel/plugin-proposal-numeric-separator",
url: "https://git.io/vb4yS"
}
},
optionalChaining: {
syntax: {
name: "@babel/plugin-syntax-optional-chaining",
url: "https://git.io/vb4Sc"
},
transform: {
name: "@babel/plugin-proposal-optional-chaining",
url: "https://git.io/vb4Sk"
}
},
pipelineOperator: {
syntax: {
name: "@babel/plugin-syntax-pipeline-operator",
url: "https://git.io/vb4yj"
},
transform: {
name: "@babel/plugin-proposal-pipeline-operator",
url: "https://git.io/vb4SU"
}
},
throwExpressions: {
syntax: {
name: "@babel/plugin-syntax-throw-expressions",
url: "https://git.io/vb4SJ"
},
transform: {
name: "@babel/plugin-proposal-throw-expressions",
url: "https://git.io/vb4yF"
}
},
typescript: {
syntax: {
name: "@babel/plugin-syntax-typescript",
url: "https://git.io/vb4SC"
},
transform: {
name: "@babel/plugin-transform-typescript",
url: "https://git.io/vb4Sm"
}
},
asyncGenerators: {
syntax: {
name: "@babel/plugin-syntax-async-generators",
url: "https://git.io/vb4SY"
},
transform: {
name: "@babel/plugin-proposal-async-generator-functions",
url: "https://git.io/vb4yp"
}
},
objectRestSpread: {
syntax: {
name: "@babel/plugin-syntax-object-rest-spread",
url: "https://git.io/vb4y5"
},
transform: {
name: "@babel/plugin-proposal-object-rest-spread",
url: "https://git.io/vb4Ss"
}
},
optionalCatchBinding: {
syntax: {
name: "@babel/plugin-syntax-optional-catch-binding",
url: "https://git.io/vb4Sn"
},
transform: {
name: "@babel/plugin-proposal-optional-catch-binding",
url: "https://git.io/vb4SI"
}
}
};
const getNameURLCombination = ({
name,
url
}) => `${name} (${url})`;
function generateMissingPluginMessage(missingPluginName, loc, codeFrame) {
let helpMessage = `Support for the experimental syntax '${missingPluginName}' isn't currently enabled ` + `(${loc.line}:${loc.column + 1}):\n\n` + codeFrame;
const pluginInfo = pluginNameMap[missingPluginName];
if (pluginInfo) {
const {
syntax: syntaxPlugin,
transform: transformPlugin
} = pluginInfo;
if (syntaxPlugin) {
if (transformPlugin) {
const transformPluginInfo = getNameURLCombination(transformPlugin);
helpMessage += `\n\nAdd ${transformPluginInfo} to the 'plugins' section of your Babel config ` + `to enable transformation.`;
} else {
const syntaxPluginInfo = getNameURLCombination(syntaxPlugin);
helpMessage += `\n\nAdd ${syntaxPluginInfo} to the 'plugins' section of your Babel config ` + `to enable parsing.`;
}
}
}
return helpMessage;
}
\ No newline at end of file
{ {
"_from": "@babel/core@^7.5.4", "name": "@babel/core",
"_id": "@babel/core@7.7.2", "version": "7.14.6",
"_inBundle": false,
"_integrity": "sha512-eeD7VEZKfhK1KUXGiyPFettgF3m513f8FoBSWiQ1xTvl1RAopLs42Wp9+Ze911I6H0N9lNqJMDgoZT7gHsipeQ==",
"_location": "/@babel/core",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/core@^7.5.4",
"name": "@babel/core",
"escapedName": "@babel%2fcore",
"scope": "@babel",
"rawSpec": "^7.5.4",
"saveSpec": null,
"fetchSpec": "^7.5.4"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/@babel/core/-/core-7.7.2.tgz",
"_shasum": "ea5b99693bcfc058116f42fa1dd54da412b29d91",
"_spec": "@babel/core@^7.5.4",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev",
"author": {
"name": "Sebastian McKenzie",
"email": "sebmck@gmail.com"
},
"browser": {
"./lib/config/files/index.js": "./lib/config/files/index-browser.js",
"./lib/transform-file.js": "./lib/transform-file-browser.js"
},
"bundleDependencies": false,
"dependencies": {
"@babel/code-frame": "^7.5.5",
"@babel/generator": "^7.7.2",
"@babel/helpers": "^7.7.0",
"@babel/parser": "^7.7.2",
"@babel/template": "^7.7.0",
"@babel/traverse": "^7.7.2",
"@babel/types": "^7.7.2",
"convert-source-map": "^1.7.0",
"debug": "^4.1.0",
"json5": "^2.1.0",
"lodash": "^4.17.13",
"resolve": "^1.3.2",
"semver": "^5.4.1",
"source-map": "^0.5.0"
},
"deprecated": false,
"description": "Babel compiler core.", "description": "Babel compiler core.",
"devDependencies": { "main": "./lib/index.js",
"@babel/helper-transform-fixture-test-runner": "^7.6.4" "author": "The Babel Team (https://babel.dev/team)",
"license": "MIT",
"publishConfig": {
"access": "public"
}, },
"engines": { "repository": {
"node": ">=6.9.0" "type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-core"
}, },
"gitHead": "35f4d1276310bac6fede4a6f86a5c76f951e179e", "homepage": "https://babel.dev/docs/en/next/babel-core",
"homepage": "https://babeljs.io/", "bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20core%22+is%3Aopen",
"keywords": [ "keywords": [
"6to5", "6to5",
"babel", "babel",
...@@ -73,15 +30,47 @@ ...@@ -73,15 +30,47 @@
"babel-core", "babel-core",
"compiler" "compiler"
], ],
"license": "MIT", "engines": {
"main": "lib/index.js", "node": ">=6.9.0"
"name": "@babel/core",
"publishConfig": {
"access": "public"
}, },
"repository": { "funding": {
"type": "git", "type": "opencollective",
"url": "https://github.com/babel/babel/tree/master/packages/babel-core" "url": "https://opencollective.com/babel"
}, },
"version": "7.7.2" "browser": {
} "./lib/config/files/index.js": "./lib/config/files/index-browser.js",
"./lib/config/resolve-targets.js": "./lib/config/resolve-targets-browser.js",
"./lib/transform-file.js": "./lib/transform-file-browser.js",
"./lib/transformation/util/clone-deep.js": "./lib/transformation/util/clone-deep-browser.js",
"./src/config/files/index.ts": "./src/config/files/index-browser.ts",
"./src/config/resolve-targets.ts": "./src/config/resolve-targets-browser.ts",
"./src/transform-file.ts": "./src/transform-file-browser.ts",
"./src/transformation/util/clone-deep.ts": "./src/transformation/util/clone-deep-browser.ts"
},
"dependencies": {
"@babel/code-frame": "^7.14.5",
"@babel/generator": "^7.14.5",
"@babel/helper-compilation-targets": "^7.14.5",
"@babel/helper-module-transforms": "^7.14.5",
"@babel/helpers": "^7.14.6",
"@babel/parser": "^7.14.6",
"@babel/template": "^7.14.5",
"@babel/traverse": "^7.14.5",
"@babel/types": "^7.14.5",
"convert-source-map": "^1.7.0",
"debug": "^4.1.0",
"gensync": "^1.0.0-beta.2",
"json5": "^2.1.2",
"semver": "^6.3.0",
"source-map": "^0.5.0"
},
"devDependencies": {
"@babel/helper-transform-fixture-test-runner": "7.14.5",
"@babel/plugin-transform-modules-commonjs": "7.14.5",
"@types/convert-source-map": "^1.5.1",
"@types/debug": "^4.1.0",
"@types/resolve": "^1.3.2",
"@types/semver": "^5.4.0",
"@types/source-map": "^0.5.0"
}
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
> Turns an AST into code. > Turns an AST into code.
See our website [@babel/generator](https://babeljs.io/docs/en/next/babel-generator.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20generator%22+is%3Aopen) associated with this package. See our website [@babel/generator](https://babeljs.io/docs/en/babel-generator) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20generator%22+is%3Aopen) associated with this package.
## Install ## Install
......
...@@ -33,7 +33,7 @@ class Buffer { ...@@ -33,7 +33,7 @@ class Buffer {
const result = { const result = {
code: this._buf.join("").trimRight(), code: this._buf.join("").trimRight(),
map: null, map: null,
rawMappings: map && map.getRawMappings() rawMappings: map == null ? void 0 : map.getRawMappings()
}; };
if (map) { if (map) {
...@@ -93,26 +93,41 @@ class Buffer { ...@@ -93,26 +93,41 @@ class Buffer {
_flush() { _flush() {
let item; let item;
while (item = this._queue.pop()) this._append(...item); while (item = this._queue.pop()) {
this._append(...item);
}
} }
_append(str, line, column, identifierName, filename, force) { _append(str, line, column, identifierName, filename, force) {
if (this._map && str[0] !== "\n") {
this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force);
}
this._buf.push(str); this._buf.push(str);
this._last = str[str.length - 1]; this._last = str[str.length - 1];
let i = str.indexOf("\n");
let last = 0;
for (let i = 0; i < str.length; i++) { if (i !== 0) {
if (str[i] === "\n") { this._mark(line, column, identifierName, filename, force);
this._position.line++; }
this._position.column = 0;
} else { while (i !== -1) {
this._position.column++; this._position.line++;
this._position.column = 0;
last = i + 1;
if (last < str.length) {
this._mark(++line, 0, identifierName, filename, force);
} }
i = str.indexOf("\n", last);
} }
this._position.column += str.length - last;
}
_mark(line, column, identifierName, filename, force) {
var _this$_map;
(_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force);
} }
removeTrailingNewline() { removeTrailingNewline() {
...@@ -208,10 +223,10 @@ class Buffer { ...@@ -208,10 +223,10 @@ class Buffer {
const origLine = targetObj.line; const origLine = targetObj.line;
const origColumn = targetObj.column; const origColumn = targetObj.column;
const origFilename = targetObj.filename; const origFilename = targetObj.filename;
targetObj.identifierName = prop === "start" && loc && loc.identifierName || null; targetObj.identifierName = prop === "start" && (loc == null ? void 0 : loc.identifierName) || null;
targetObj.line = pos ? pos.line : null; targetObj.line = pos == null ? void 0 : pos.line;
targetObj.column = pos ? pos.column : null; targetObj.column = pos == null ? void 0 : pos.column;
targetObj.filename = loc && loc.filename || null; targetObj.filename = loc == null ? void 0 : loc.filename;
if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) { if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) {
targetObj.force = force; targetObj.force = force;
......
...@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { ...@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", {
exports.File = File; exports.File = File;
exports.Program = Program; exports.Program = Program;
exports.BlockStatement = BlockStatement; exports.BlockStatement = BlockStatement;
exports.Noop = Noop;
exports.Directive = Directive; exports.Directive = Directive;
exports.DirectiveLiteral = DirectiveLiteral; exports.DirectiveLiteral = DirectiveLiteral;
exports.InterpreterDirective = InterpreterDirective; exports.InterpreterDirective = InterpreterDirective;
exports.Placeholder = Placeholder; exports.Placeholder = Placeholder;
var t = require("@babel/types");
function File(node) { function File(node) {
if (node.program) { if (node.program) {
this.print(node.program.interpreter, node); this.print(node.program.interpreter, node);
...@@ -28,9 +29,11 @@ function Program(node) { ...@@ -28,9 +29,11 @@ function Program(node) {
} }
function BlockStatement(node) { function BlockStatement(node) {
var _node$directives;
this.token("{"); this.token("{");
this.printInnerComments(node); this.printInnerComments(node);
const hasDirectives = node.directives && node.directives.length; const hasDirectives = (_node$directives = node.directives) == null ? void 0 : _node$directives.length;
if (node.body.length || hasDirectives) { if (node.body.length || hasDirectives) {
this.newline(); this.newline();
...@@ -51,8 +54,6 @@ function BlockStatement(node) { ...@@ -51,8 +54,6 @@ function BlockStatement(node) {
} }
} }
function Noop() {}
function Directive(node) { function Directive(node) {
this.print(node.value, node); this.print(node.value, node);
this.semicolon(); this.semicolon();
......
...@@ -10,12 +10,9 @@ exports.ClassPrivateProperty = ClassPrivateProperty; ...@@ -10,12 +10,9 @@ exports.ClassPrivateProperty = ClassPrivateProperty;
exports.ClassMethod = ClassMethod; exports.ClassMethod = ClassMethod;
exports.ClassPrivateMethod = ClassPrivateMethod; exports.ClassPrivateMethod = ClassPrivateMethod;
exports._classMethodHead = _classMethodHead; exports._classMethodHead = _classMethodHead;
exports.StaticBlock = StaticBlock;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function ClassDeclaration(node, parent) { function ClassDeclaration(node, parent) {
if (!this.format.decoratorsBeforeExport || !t.isExportDefaultDeclaration(parent) && !t.isExportNamedDeclaration(parent)) { if (!this.format.decoratorsBeforeExport || !t.isExportDefaultDeclaration(parent) && !t.isExportNamedDeclaration(parent)) {
...@@ -78,6 +75,7 @@ function ClassBody(node) { ...@@ -78,6 +75,7 @@ function ClassBody(node) {
function ClassProperty(node) { function ClassProperty(node) {
this.printJoin(node.decorators, node); this.printJoin(node.decorators, node);
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node, true); this.tsPrintClassMemberModifiers(node, true);
if (node.computed) { if (node.computed) {
...@@ -111,6 +109,8 @@ function ClassProperty(node) { ...@@ -111,6 +109,8 @@ function ClassProperty(node) {
} }
function ClassPrivateProperty(node) { function ClassPrivateProperty(node) {
this.printJoin(node.decorators, node);
if (node.static) { if (node.static) {
this.word("static"); this.word("static");
this.space(); this.space();
...@@ -145,7 +145,24 @@ function ClassPrivateMethod(node) { ...@@ -145,7 +145,24 @@ function ClassPrivateMethod(node) {
function _classMethodHead(node) { function _classMethodHead(node) {
this.printJoin(node.decorators, node); this.printJoin(node.decorators, node);
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node, false); this.tsPrintClassMemberModifiers(node, false);
this._methodHead(node); this._methodHead(node);
}
function StaticBlock(node) {
this.word("static");
this.space();
this.token("{");
if (node.body.length === 0) {
this.token("}");
} else {
this.newline();
this.printSequence(node.body, node, {
indent: true
});
this.rightBrace();
}
} }
\ No newline at end of file
...@@ -26,15 +26,12 @@ exports.MemberExpression = MemberExpression; ...@@ -26,15 +26,12 @@ exports.MemberExpression = MemberExpression;
exports.MetaProperty = MetaProperty; exports.MetaProperty = MetaProperty;
exports.PrivateName = PrivateName; exports.PrivateName = PrivateName;
exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier; exports.V8IntrinsicIdentifier = V8IntrinsicIdentifier;
exports.ModuleExpression = ModuleExpression;
exports.AwaitExpression = exports.YieldExpression = void 0; exports.AwaitExpression = exports.YieldExpression = void 0;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var n = _interopRequireWildcard(require("../node")); var n = require("../node");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function UnaryExpression(node) { function UnaryExpression(node) {
if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof" || node.operator === "throw") { if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof" || node.operator === "throw") {
...@@ -48,6 +45,11 @@ function UnaryExpression(node) { ...@@ -48,6 +45,11 @@ function UnaryExpression(node) {
} }
function DoExpression(node) { function DoExpression(node) {
if (node.async) {
this.word("async");
this.space();
}
this.word("do"); this.word("do");
this.space(); this.space();
this.print(node.body, node); this.print(node.body, node);
...@@ -289,4 +291,20 @@ function PrivateName(node) { ...@@ -289,4 +291,20 @@ function PrivateName(node) {
function V8IntrinsicIdentifier(node) { function V8IntrinsicIdentifier(node) {
this.token("%"); this.token("%");
this.word(node.name); this.word(node.name);
}
function ModuleExpression(node) {
this.word("module");
this.space();
this.token("{");
if (node.body.body.length === 0) {
this.token("}");
} else {
this.newline();
this.printSequence(node.body.body, node, {
indent: true
});
this.rightBrace();
}
} }
\ No newline at end of file
...@@ -58,10 +58,13 @@ exports.ObjectTypeIndexer = ObjectTypeIndexer; ...@@ -58,10 +58,13 @@ exports.ObjectTypeIndexer = ObjectTypeIndexer;
exports.ObjectTypeProperty = ObjectTypeProperty; exports.ObjectTypeProperty = ObjectTypeProperty;
exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty; exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier; exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
exports.SymbolTypeAnnotation = SymbolTypeAnnotation;
exports.UnionTypeAnnotation = UnionTypeAnnotation; exports.UnionTypeAnnotation = UnionTypeAnnotation;
exports.TypeCastExpression = TypeCastExpression; exports.TypeCastExpression = TypeCastExpression;
exports.Variance = Variance; exports.Variance = Variance;
exports.VoidTypeAnnotation = VoidTypeAnnotation; exports.VoidTypeAnnotation = VoidTypeAnnotation;
exports.IndexedAccessType = IndexedAccessType;
exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
Object.defineProperty(exports, "NumberLiteralTypeAnnotation", { Object.defineProperty(exports, "NumberLiteralTypeAnnotation", {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -75,16 +78,12 @@ Object.defineProperty(exports, "StringLiteralTypeAnnotation", { ...@@ -75,16 +78,12 @@ Object.defineProperty(exports, "StringLiteralTypeAnnotation", {
} }
}); });
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var _modules = require("./modules"); var _modules = require("./modules");
var _types2 = require("./types"); var _types2 = require("./types");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function AnyTypeAnnotation() { function AnyTypeAnnotation() {
this.word("any"); this.word("any");
} }
...@@ -260,6 +259,11 @@ function enumBody(context, node) { ...@@ -260,6 +259,11 @@ function enumBody(context, node) {
context.newline(); context.newline();
} }
if (node.hasUnknownMembers) {
context.token("...");
context.newline();
}
context.dedent(); context.dedent();
context.token("}"); context.token("}");
} }
...@@ -360,6 +364,19 @@ function ExistsTypeAnnotation() { ...@@ -360,6 +364,19 @@ function ExistsTypeAnnotation() {
function FunctionTypeAnnotation(node, parent) { function FunctionTypeAnnotation(node, parent) {
this.print(node.typeParameters, node); this.print(node.typeParameters, node);
this.token("("); this.token("(");
if (node.this) {
this.word("this");
this.token(":");
this.space();
this.print(node.this.typeAnnotation, node);
if (node.params.length || node.rest) {
this.token(",");
this.space();
}
}
this.printList(node.params, node); this.printList(node.params, node);
if (node.rest) { if (node.rest) {
...@@ -403,10 +420,12 @@ function InterfaceExtends(node) { ...@@ -403,10 +420,12 @@ function InterfaceExtends(node) {
} }
function _interfaceish(node) { function _interfaceish(node) {
var _node$extends;
this.print(node.id, node); this.print(node.id, node);
this.print(node.typeParameters, node); this.print(node.typeParameters, node);
if (node.extends.length) { if ((_node$extends = node.extends) != null && _node$extends.length) {
this.space(); this.space();
this.word("extends"); this.word("extends");
this.space(); this.space();
...@@ -584,7 +603,7 @@ function ObjectTypeAnnotation(node) { ...@@ -584,7 +603,7 @@ function ObjectTypeAnnotation(node) {
this.token("{"); this.token("{");
} }
const props = node.properties.concat(node.callProperties || [], node.indexers || [], node.internalSlots || []); const props = [...node.properties, ...(node.callProperties || []), ...(node.indexers || []), ...(node.internalSlots || [])];
if (props.length) { if (props.length) {
this.space(); this.space();
...@@ -687,6 +706,11 @@ function ObjectTypeProperty(node) { ...@@ -687,6 +706,11 @@ function ObjectTypeProperty(node) {
this.space(); this.space();
} }
if (node.kind === "get" || node.kind === "set") {
this.word(node.kind);
this.space();
}
this._variance(node); this._variance(node);
this.print(node.key, node); this.print(node.key, node);
...@@ -711,6 +735,10 @@ function QualifiedTypeIdentifier(node) { ...@@ -711,6 +735,10 @@ function QualifiedTypeIdentifier(node) {
this.print(node.id, node); this.print(node.id, node);
} }
function SymbolTypeAnnotation() {
this.word("symbol");
}
function orSeparator() { function orSeparator() {
this.space(); this.space();
this.token("|"); this.token("|");
...@@ -740,4 +768,23 @@ function Variance(node) { ...@@ -740,4 +768,23 @@ function Variance(node) {
function VoidTypeAnnotation() { function VoidTypeAnnotation() {
this.word("void"); this.word("void");
}
function IndexedAccessType(node) {
this.print(node.objectType, node);
this.token("[");
this.print(node.indexType, node);
this.token("]");
}
function OptionalIndexedAccessType(node) {
this.print(node.objectType, node);
if (node.optional) {
this.token("?.");
}
this.token("[");
this.print(node.indexType, node);
this.token("]");
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ var _templateLiterals = require("./template-literals"); ...@@ -8,6 +8,7 @@ var _templateLiterals = require("./template-literals");
Object.keys(_templateLiterals).forEach(function (key) { Object.keys(_templateLiterals).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _templateLiterals[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -20,6 +21,7 @@ var _expressions = require("./expressions"); ...@@ -20,6 +21,7 @@ var _expressions = require("./expressions");
Object.keys(_expressions).forEach(function (key) { Object.keys(_expressions).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _expressions[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -32,6 +34,7 @@ var _statements = require("./statements"); ...@@ -32,6 +34,7 @@ var _statements = require("./statements");
Object.keys(_statements).forEach(function (key) { Object.keys(_statements).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _statements[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -44,6 +47,7 @@ var _classes = require("./classes"); ...@@ -44,6 +47,7 @@ var _classes = require("./classes");
Object.keys(_classes).forEach(function (key) { Object.keys(_classes).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _classes[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -56,6 +60,7 @@ var _methods = require("./methods"); ...@@ -56,6 +60,7 @@ var _methods = require("./methods");
Object.keys(_methods).forEach(function (key) { Object.keys(_methods).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _methods[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -68,6 +73,7 @@ var _modules = require("./modules"); ...@@ -68,6 +73,7 @@ var _modules = require("./modules");
Object.keys(_modules).forEach(function (key) { Object.keys(_modules).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _modules[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -80,6 +86,7 @@ var _types = require("./types"); ...@@ -80,6 +86,7 @@ var _types = require("./types");
Object.keys(_types).forEach(function (key) { Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -92,6 +99,7 @@ var _flow = require("./flow"); ...@@ -92,6 +99,7 @@ var _flow = require("./flow");
Object.keys(_flow).forEach(function (key) { Object.keys(_flow).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _flow[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -104,6 +112,7 @@ var _base = require("./base"); ...@@ -104,6 +112,7 @@ var _base = require("./base");
Object.keys(_base).forEach(function (key) { Object.keys(_base).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _base[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -116,6 +125,7 @@ var _jsx = require("./jsx"); ...@@ -116,6 +125,7 @@ var _jsx = require("./jsx");
Object.keys(_jsx).forEach(function (key) { Object.keys(_jsx).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _jsx[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -128,6 +138,7 @@ var _typescript = require("./typescript"); ...@@ -128,6 +138,7 @@ var _typescript = require("./typescript");
Object.keys(_typescript).forEach(function (key) { Object.keys(_typescript).forEach(function (key) {
if (key === "default" || key === "__esModule") return; if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _typescript[key]) return;
Object.defineProperty(exports, key, { Object.defineProperty(exports, key, {
enumerable: true, enumerable: true,
get: function () { get: function () {
......
...@@ -19,6 +19,8 @@ exports.JSXFragment = JSXFragment; ...@@ -19,6 +19,8 @@ exports.JSXFragment = JSXFragment;
exports.JSXOpeningFragment = JSXOpeningFragment; exports.JSXOpeningFragment = JSXOpeningFragment;
exports.JSXClosingFragment = JSXClosingFragment; exports.JSXClosingFragment = JSXClosingFragment;
var t = require("@babel/types");
function JSXAttribute(node) { function JSXAttribute(node) {
this.print(node.name, node); this.print(node.name, node);
......
...@@ -12,11 +12,7 @@ exports._functionHead = _functionHead; ...@@ -12,11 +12,7 @@ exports._functionHead = _functionHead;
exports.FunctionDeclaration = exports.FunctionExpression = FunctionExpression; exports.FunctionDeclaration = exports.FunctionExpression = FunctionExpression;
exports.ArrowFunctionExpression = ArrowFunctionExpression; exports.ArrowFunctionExpression = ArrowFunctionExpression;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _params(node) { function _params(node) {
this.print(node.typeParameters, node); this.print(node.typeParameters, node);
...@@ -56,6 +52,8 @@ function _methodHead(node) { ...@@ -56,6 +52,8 @@ function _methodHead(node) {
} }
if (node.async) { if (node.async) {
this._catchUp("start", key.loc);
this.word("async"); this.word("async");
this.space(); this.space();
} }
...@@ -126,24 +124,8 @@ function ArrowFunctionExpression(node) { ...@@ -126,24 +124,8 @@ function ArrowFunctionExpression(node) {
const firstParam = node.params[0]; const firstParam = node.params[0];
if (node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypes(node, firstParam)) { if (!this.format.retainLines && !this.format.auxiliaryCommentBefore && !this.format.auxiliaryCommentAfter && node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypesOrComments(node, firstParam)) {
if (this.format.retainLines && node.loc && node.body.loc && node.loc.start.line < node.body.loc.start.line) { this.print(firstParam, node);
this.token("(");
if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) {
this.indent();
this.print(firstParam, node);
this.dedent();
this._catchUp("start", node.body.loc);
} else {
this.print(firstParam, node);
}
this.token(")");
} else {
this.print(firstParam, node);
}
} else { } else {
this._params(node); this._params(node);
} }
...@@ -156,6 +138,8 @@ function ArrowFunctionExpression(node) { ...@@ -156,6 +138,8 @@ function ArrowFunctionExpression(node) {
this.print(node.body, node); this.print(node.body, node);
} }
function hasTypes(node, param) { function hasTypesOrComments(node, param) {
return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments; var _param$leadingComment, _param$trailingCommen;
return !!(node.typeParameters || node.returnType || node.predicate || param.typeAnnotation || param.optional || (_param$leadingComment = param.leadingComments) != null && _param$leadingComment.length || (_param$trailingCommen = param.trailingComments) != null && _param$trailingCommen.length);
} }
\ No newline at end of file
...@@ -12,13 +12,10 @@ exports.ExportAllDeclaration = ExportAllDeclaration; ...@@ -12,13 +12,10 @@ exports.ExportAllDeclaration = ExportAllDeclaration;
exports.ExportNamedDeclaration = ExportNamedDeclaration; exports.ExportNamedDeclaration = ExportNamedDeclaration;
exports.ExportDefaultDeclaration = ExportDefaultDeclaration; exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
exports.ImportDeclaration = ImportDeclaration; exports.ImportDeclaration = ImportDeclaration;
exports.ImportAttribute = ImportAttribute;
exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier; exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function ImportSpecifier(node) { function ImportSpecifier(node) {
if (node.importKind === "type" || node.importKind === "typeof") { if (node.importKind === "type" || node.importKind === "typeof") {
...@@ -77,6 +74,7 @@ function ExportAllDeclaration(node) { ...@@ -77,6 +74,7 @@ function ExportAllDeclaration(node) {
this.word("from"); this.word("from");
this.space(); this.space();
this.print(node.source, node); this.print(node.source, node);
this.printAssertions(node);
this.semicolon(); this.semicolon();
} }
...@@ -116,7 +114,7 @@ function ExportDeclaration(node) { ...@@ -116,7 +114,7 @@ function ExportDeclaration(node) {
const specifiers = node.specifiers.slice(0); const specifiers = node.specifiers.slice(0);
let hasSpecial = false; let hasSpecial = false;
while (true) { for (;;) {
const first = specifiers[0]; const first = specifiers[0];
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
...@@ -149,6 +147,7 @@ function ExportDeclaration(node) { ...@@ -149,6 +147,7 @@ function ExportDeclaration(node) {
this.word("from"); this.word("from");
this.space(); this.space();
this.print(node.source, node); this.print(node.source, node);
this.printAssertions(node);
} }
this.semicolon(); this.semicolon();
...@@ -166,8 +165,8 @@ function ImportDeclaration(node) { ...@@ -166,8 +165,8 @@ function ImportDeclaration(node) {
const specifiers = node.specifiers.slice(0); const specifiers = node.specifiers.slice(0);
if (specifiers && specifiers.length) { if (specifiers != null && specifiers.length) {
while (true) { for (;;) {
const first = specifiers[0]; const first = specifiers[0];
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
...@@ -196,9 +195,27 @@ function ImportDeclaration(node) { ...@@ -196,9 +195,27 @@ function ImportDeclaration(node) {
} }
this.print(node.source, node); this.print(node.source, node);
this.printAssertions(node);
{
var _node$attributes;
if ((_node$attributes = node.attributes) != null && _node$attributes.length) {
this.space();
this.word("with");
this.space();
this.printList(node.attributes, node);
}
}
this.semicolon(); this.semicolon();
} }
function ImportAttribute(node) {
this.print(node.key);
this.token(":");
this.space();
this.print(node.value);
}
function ImportNamespaceSpecifier(node) { function ImportNamespaceSpecifier(node) {
this.token("*"); this.token("*");
this.space(); this.space();
......
...@@ -18,11 +18,7 @@ exports.VariableDeclaration = VariableDeclaration; ...@@ -18,11 +18,7 @@ exports.VariableDeclaration = VariableDeclaration;
exports.VariableDeclarator = VariableDeclarator; exports.VariableDeclarator = VariableDeclarator;
exports.ThrowStatement = exports.BreakStatement = exports.ReturnStatement = exports.ContinueStatement = exports.ForOfStatement = exports.ForInStatement = void 0; exports.ThrowStatement = exports.BreakStatement = exports.ReturnStatement = exports.ContinueStatement = exports.ForOfStatement = exports.ForInStatement = void 0;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function WithStatement(node) { function WithStatement(node) {
this.word("with"); this.word("with");
...@@ -202,6 +198,7 @@ function CatchClause(node) { ...@@ -202,6 +198,7 @@ function CatchClause(node) {
if (node.param) { if (node.param) {
this.token("("); this.token("(");
this.print(node.param, node); this.print(node.param, node);
this.print(node.param.typeAnnotation, node);
this.token(")"); this.token(")");
this.space(); this.space();
} }
...@@ -293,7 +290,11 @@ function VariableDeclaration(node, parent) { ...@@ -293,7 +290,11 @@ function VariableDeclaration(node, parent) {
}); });
if (t.isFor(parent)) { if (t.isFor(parent)) {
if (parent.left === node || parent.init === node) return; if (t.isForStatement(parent)) {
if (parent.init === node) return;
} else {
if (parent.left === node) return;
}
} }
this.semicolon(); this.semicolon();
......
...@@ -7,6 +7,8 @@ exports.TaggedTemplateExpression = TaggedTemplateExpression; ...@@ -7,6 +7,8 @@ exports.TaggedTemplateExpression = TaggedTemplateExpression;
exports.TemplateElement = TemplateElement; exports.TemplateElement = TemplateElement;
exports.TemplateLiteral = TemplateLiteral; exports.TemplateLiteral = TemplateLiteral;
var t = require("@babel/types");
function TaggedTemplateExpression(node) { function TaggedTemplateExpression(node) {
this.print(node.tag, node); this.print(node.tag, node);
this.print(node.typeParameters, node); this.print(node.typeParameters, node);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment