Commit 0ae470fd authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

Merge branch 'MLAB-670' into 'testing'

Update required modules

See merge request !162
parents cad730bf d27c335f
Pipeline #6650 passed with stage
in 4 seconds
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = annotateAsPure;
var _t = require("@babel/types");
const {
addComment
} = _t;
const PURE_ANNOTATION = "#__PURE__";
const isPureAnnotated = ({
leadingComments
}) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
function annotateAsPure(pathOrNode) {
const node = pathOrNode["node"] || pathOrNode;
if (isPureAnnotated(node)) {
return;
}
addComment(node, "leading", PURE_ANNOTATION);
}
\ No newline at end of file
{
"name": "@babel/helper-annotate-as-pure",
"version": "7.18.6",
"description": "Helper function to annotate paths and nodes with #__PURE__ comment",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-annotate-as-pure"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-annotate-as-pure",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/types": "^7.18.6"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}
\ No newline at end of file
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/helper-builder-binary-assignment-operator-visitor
> Helper function to build binary assignment operator visitors
See our website [@babel/helper-builder-binary-assignment-operator-visitor](https://babeljs.io/docs/en/babel-helper-builder-binary-assignment-operator-visitor) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-builder-binary-assignment-operator-visitor
```
or using yarn:
```sh
yarn add @babel/helper-builder-binary-assignment-operator-visitor
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _helperExplodeAssignableExpression = require("@babel/helper-explode-assignable-expression");
var _t = require("@babel/types");
const {
assignmentExpression,
sequenceExpression
} = _t;
function _default(opts) {
const {
build,
operator
} = opts;
const visitor = {
AssignmentExpression(path) {
const {
node,
scope
} = path;
if (node.operator !== operator + "=") return;
const nodes = [];
const exploded = (0, _helperExplodeAssignableExpression.default)(node.left, nodes, this, scope);
nodes.push(assignmentExpression("=", exploded.ref, build(exploded.uid, node.right)));
path.replaceWith(sequenceExpression(nodes));
},
BinaryExpression(path) {
const {
node
} = path;
if (node.operator === operator) {
path.replaceWith(build(node.left, node.right));
}
}
};
return visitor;
}
\ No newline at end of file
{
"name": "@babel/helper-builder-binary-assignment-operator-visitor",
"version": "7.18.6",
"description": "Helper function to build binary assignment operator visitors",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-builder-binary-assignment-operator-visitor"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-builder-binary-assignment-operator-visitor",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/helper-explode-assignable-expression": "^7.18.6",
"@babel/types": "^7.18.6"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}
\ No newline at end of file
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/helper-compilation-targets
> Helper functions on Babel compilation targets
See our website [@babel/helper-compilation-targets](https://babeljs.io/docs/en/babel-helper-compilation-targets) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-compilation-targets
```
or using yarn:
```sh
yarn add @babel/helper-compilation-targets
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getInclusionReasons = getInclusionReasons;
var _semver = require("semver");
var _pretty = require("./pretty");
var _utils = require("./utils");
function getInclusionReasons(item, targetVersions, list) {
const minVersions = list[item] || {};
return Object.keys(targetVersions).reduce((result, env) => {
const minVersion = (0, _utils.getLowestImplementedVersion)(minVersions, env);
const targetVersion = targetVersions[env];
if (!minVersion) {
result[env] = (0, _pretty.prettifyVersion)(targetVersion);
} else {
const minIsUnreleased = (0, _utils.isUnreleasedVersion)(minVersion, env);
const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
if (!targetIsUnreleased && (minIsUnreleased || _semver.lt(targetVersion.toString(), (0, _utils.semverify)(minVersion)))) {
result[env] = (0, _pretty.prettifyVersion)(targetVersion);
}
}
return result;
}, {});
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = filterItems;
exports.isRequired = isRequired;
exports.targetsSupported = targetsSupported;
var _semver = require("semver");
var _plugins = require("@babel/compat-data/plugins");
var _utils = require("./utils");
function targetsSupported(target, support) {
const targetEnvironments = Object.keys(target);
if (targetEnvironments.length === 0) {
return false;
}
const unsupportedEnvironments = targetEnvironments.filter(environment => {
const lowestImplementedVersion = (0, _utils.getLowestImplementedVersion)(support, environment);
if (!lowestImplementedVersion) {
return true;
}
const lowestTargetedVersion = target[environment];
if ((0, _utils.isUnreleasedVersion)(lowestTargetedVersion, environment)) {
return false;
}
if ((0, _utils.isUnreleasedVersion)(lowestImplementedVersion, environment)) {
return true;
}
if (!_semver.valid(lowestTargetedVersion.toString())) {
throw new Error(`Invalid version passed for target "${environment}": "${lowestTargetedVersion}". ` + "Versions must be in semver format (major.minor.patch)");
}
return _semver.gt((0, _utils.semverify)(lowestImplementedVersion), lowestTargetedVersion.toString());
});
return unsupportedEnvironments.length === 0;
}
function isRequired(name, targets, {
compatData = _plugins,
includes,
excludes
} = {}) {
if (excludes != null && excludes.has(name)) return false;
if (includes != null && includes.has(name)) return true;
return !targetsSupported(targets, compatData[name]);
}
function filterItems(list, includes, excludes, targets, defaultIncludes, defaultExcludes, pluginSyntaxMap) {
const result = new Set();
const options = {
compatData: list,
includes,
excludes
};
for (const item in list) {
if (isRequired(item, targets, options)) {
result.add(item);
} else if (pluginSyntaxMap) {
const shippedProposalsSyntax = pluginSyntaxMap.get(item);
if (shippedProposalsSyntax) {
result.add(shippedProposalsSyntax);
}
}
}
if (defaultIncludes) {
defaultIncludes.forEach(item => !excludes.has(item) && result.add(item));
}
if (defaultExcludes) {
defaultExcludes.forEach(item => !includes.has(item) && result.delete(item));
}
return result;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "TargetNames", {
enumerable: true,
get: function () {
return _options.TargetNames;
}
});
exports.default = getTargets;
Object.defineProperty(exports, "filterItems", {
enumerable: true,
get: function () {
return _filterItems.default;
}
});
Object.defineProperty(exports, "getInclusionReasons", {
enumerable: true,
get: function () {
return _debug.getInclusionReasons;
}
});
exports.isBrowsersQueryValid = isBrowsersQueryValid;
Object.defineProperty(exports, "isRequired", {
enumerable: true,
get: function () {
return _filterItems.isRequired;
}
});
Object.defineProperty(exports, "prettifyTargets", {
enumerable: true,
get: function () {
return _pretty.prettifyTargets;
}
});
Object.defineProperty(exports, "unreleasedLabels", {
enumerable: true,
get: function () {
return _targets.unreleasedLabels;
}
});
var _browserslist = require("browserslist");
var _helperValidatorOption = require("@babel/helper-validator-option");
var _nativeModules = require("@babel/compat-data/native-modules");
var _utils = require("./utils");
var _targets = require("./targets");
var _options = require("./options");
var _pretty = require("./pretty");
var _debug = require("./debug");
var _filterItems = require("./filter-items");
const ESM_SUPPORT = _nativeModules["es6.module"];
const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
function validateTargetNames(targets) {
const validTargets = Object.keys(_options.TargetNames);
for (const target of Object.keys(targets)) {
if (!(target in _options.TargetNames)) {
throw new Error(v.formatMessage(`'${target}' is not a valid target
- Did you mean '${(0, _helperValidatorOption.findSuggestion)(target, validTargets)}'?`));
}
}
return targets;
}
function isBrowsersQueryValid(browsers) {
return typeof browsers === "string" || Array.isArray(browsers) && browsers.every(b => typeof b === "string");
}
function validateBrowsers(browsers) {
v.invariant(browsers === undefined || isBrowsersQueryValid(browsers), `'${String(browsers)}' is not a valid browserslist query`);
return browsers;
}
function getLowestVersions(browsers) {
return browsers.reduce((all, browser) => {
const [browserName, browserVersion] = browser.split(" ");
const target = _targets.browserNameMap[browserName];
if (!target) {
return all;
}
try {
const splitVersion = browserVersion.split("-")[0].toLowerCase();
const isSplitUnreleased = (0, _utils.isUnreleasedVersion)(splitVersion, target);
if (!all[target]) {
all[target] = isSplitUnreleased ? splitVersion : (0, _utils.semverify)(splitVersion);
return all;
}
const version = all[target];
const isUnreleased = (0, _utils.isUnreleasedVersion)(version, target);
if (isUnreleased && isSplitUnreleased) {
all[target] = (0, _utils.getLowestUnreleased)(version, splitVersion, target);
} else if (isUnreleased) {
all[target] = (0, _utils.semverify)(splitVersion);
} else if (!isUnreleased && !isSplitUnreleased) {
const parsedBrowserVersion = (0, _utils.semverify)(splitVersion);
all[target] = (0, _utils.semverMin)(version, parsedBrowserVersion);
}
} catch (e) {}
return all;
}, {});
}
function outputDecimalWarning(decimalTargets) {
if (!decimalTargets.length) {
return;
}
console.warn("Warning, the following targets are using a decimal version:\n");
decimalTargets.forEach(({
target,
value
}) => console.warn(` ${target}: ${value}`));
console.warn(`
We recommend using a string for minor/patch versions to avoid numbers like 6.10
getting parsed as 6.1, which can lead to unexpected behavior.
`);
}
function semverifyTarget(target, value) {
try {
return (0, _utils.semverify)(value);
} catch (error) {
throw new Error(v.formatMessage(`'${value}' is not a valid value for 'targets.${target}'.`));
}
}
function nodeTargetParser(value) {
const parsed = value === true || value === "current" ? process.versions.node : semverifyTarget("node", value);
return ["node", parsed];
}
function defaultTargetParser(target, value) {
const version = (0, _utils.isUnreleasedVersion)(value, target) ? value.toLowerCase() : semverifyTarget(target, value);
return [target, version];
}
function generateTargets(inputTargets) {
const input = Object.assign({}, inputTargets);
delete input.esmodules;
delete input.browsers;
return input;
}
function resolveTargets(queries, env) {
const resolved = _browserslist(queries, {
mobileToDesktop: true,
env
});
return getLowestVersions(resolved);
}
function getTargets(inputTargets = {}, options = {}) {
var _browsers, _browsers2;
let {
browsers,
esmodules
} = inputTargets;
const {
configPath = "."
} = options;
validateBrowsers(browsers);
const input = generateTargets(inputTargets);
let targets = validateTargetNames(input);
const shouldParseBrowsers = !!browsers;
const hasTargets = shouldParseBrowsers || Object.keys(targets).length > 0;
const shouldSearchForConfig = !options.ignoreBrowserslistConfig && !hasTargets;
if (!browsers && shouldSearchForConfig) {
browsers = _browserslist.loadConfig({
config: options.configFile,
path: configPath,
env: options.browserslistEnv
});
if (browsers == null) {
{
browsers = [];
}
}
}
if (esmodules && (esmodules !== "intersect" || !((_browsers = browsers) != null && _browsers.length))) {
browsers = Object.keys(ESM_SUPPORT).map(browser => `${browser} >= ${ESM_SUPPORT[browser]}`).join(", ");
esmodules = false;
}
if ((_browsers2 = browsers) != null && _browsers2.length) {
const queryBrowsers = resolveTargets(browsers, options.browserslistEnv);
if (esmodules === "intersect") {
for (const browser of Object.keys(queryBrowsers)) {
const version = queryBrowsers[browser];
const esmSupportVersion = ESM_SUPPORT[browser];
if (esmSupportVersion) {
queryBrowsers[browser] = (0, _utils.getHighestUnreleased)(version, (0, _utils.semverify)(esmSupportVersion), browser);
} else {
delete queryBrowsers[browser];
}
}
}
targets = Object.assign(queryBrowsers, targets);
}
const result = {};
const decimalWarnings = [];
for (const target of Object.keys(targets).sort()) {
const value = targets[target];
if (typeof value === "number" && value % 1 !== 0) {
decimalWarnings.push({
target,
value
});
}
const [parsedTarget, parsedValue] = target === "node" ? nodeTargetParser(value) : defaultTargetParser(target, value);
if (parsedValue) {
result[parsedTarget] = parsedValue;
}
}
outputDecimalWarning(decimalWarnings);
return result;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TargetNames = void 0;
const TargetNames = {
node: "node",
chrome: "chrome",
opera: "opera",
edge: "edge",
firefox: "firefox",
safari: "safari",
ie: "ie",
ios: "ios",
android: "android",
electron: "electron",
samsung: "samsung",
rhino: "rhino"
};
exports.TargetNames = TargetNames;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.prettifyTargets = prettifyTargets;
exports.prettifyVersion = prettifyVersion;
var _semver = require("semver");
var _targets = require("./targets");
function prettifyVersion(version) {
if (typeof version !== "string") {
return version;
}
const parts = [_semver.major(version)];
const minor = _semver.minor(version);
const patch = _semver.patch(version);
if (minor || patch) {
parts.push(minor);
}
if (patch) {
parts.push(patch);
}
return parts.join(".");
}
function prettifyTargets(targets) {
return Object.keys(targets).reduce((results, target) => {
let value = targets[target];
const unreleasedLabel = _targets.unreleasedLabels[target];
if (typeof value === "string" && unreleasedLabel !== value) {
value = prettifyVersion(value);
}
results[target] = value;
return results;
}, {});
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.unreleasedLabels = exports.browserNameMap = void 0;
const unreleasedLabels = {
safari: "tp"
};
exports.unreleasedLabels = unreleasedLabels;
const browserNameMap = {
and_chr: "chrome",
and_ff: "firefox",
android: "android",
chrome: "chrome",
edge: "edge",
firefox: "firefox",
ie: "ie",
ie_mob: "ie",
ios_saf: "ios",
node: "node",
op_mob: "opera",
opera: "opera",
safari: "safari",
samsung: "samsung"
};
exports.browserNameMap = browserNameMap;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getHighestUnreleased = getHighestUnreleased;
exports.getLowestImplementedVersion = getLowestImplementedVersion;
exports.getLowestUnreleased = getLowestUnreleased;
exports.isUnreleasedVersion = isUnreleasedVersion;
exports.semverMin = semverMin;
exports.semverify = semverify;
var _semver = require("semver");
var _helperValidatorOption = require("@babel/helper-validator-option");
var _targets = require("./targets");
const versionRegExp = /^(\d+|\d+.\d+)$/;
const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
function semverMin(first, second) {
return first && _semver.lt(first, second) ? first : second;
}
function semverify(version) {
if (typeof version === "string" && _semver.valid(version)) {
return version;
}
v.invariant(typeof version === "number" || typeof version === "string" && versionRegExp.test(version), `'${version}' is not a valid version`);
const split = version.toString().split(".");
while (split.length < 3) {
split.push("0");
}
return split.join(".");
}
function isUnreleasedVersion(version, env) {
const unreleasedLabel = _targets.unreleasedLabels[env];
return !!unreleasedLabel && unreleasedLabel === version.toString().toLowerCase();
}
function getLowestUnreleased(a, b, env) {
const unreleasedLabel = _targets.unreleasedLabels[env];
if (a === unreleasedLabel) {
return b;
}
if (b === unreleasedLabel) {
return a;
}
return semverMin(a, b);
}
function getHighestUnreleased(a, b, env) {
return getLowestUnreleased(a, b, env) === a ? b : a;
}
function getLowestImplementedVersion(plugin, environment) {
const result = plugin[environment];
if (!result && environment === "android") {
return plugin.chrome;
}
return result;
}
\ No newline at end of file
{
"name": "@babel/helper-compilation-targets",
"version": "7.18.6",
"author": "The Babel Team (https://babel.dev/team)",
"license": "MIT",
"description": "Helper functions on Babel compilation targets",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-compilation-targets"
},
"main": "./lib/index.js",
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"babel",
"babel-plugin"
],
"dependencies": {
"@babel/compat-data": "^7.18.6",
"@babel/helper-validator-option": "^7.18.6",
"browserslist": "^4.20.2",
"semver": "^6.3.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/helper-plugin-test-runner": "^7.18.6",
"@types/semver": "^5.5.0"
},
"engines": {
"node": ">=6.9.0"
},
"type": "commonjs"
}
\ No newline at end of file
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/helper-create-class-features-plugin
> Compile class public and private fields, private methods and decorators to ES6
See our website [@babel/helper-create-class-features-plugin](https://babeljs.io/docs/en/babel-helper-create-class-features-plugin) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-create-class-features-plugin
```
or using yarn:
```sh
yarn add @babel/helper-create-class-features-plugin
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildDecoratedClass = buildDecoratedClass;
exports.hasDecorators = hasDecorators;
exports.hasOwnDecorators = hasOwnDecorators;
var _core = require("@babel/core");
var _helperReplaceSupers = require("@babel/helper-replace-supers");
var _helperFunctionName = require("@babel/helper-function-name");
function hasOwnDecorators(node) {
return !!(node.decorators && node.decorators.length);
}
function hasDecorators(node) {
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators);
}
function prop(key, value) {
if (!value) return null;
return _core.types.objectProperty(_core.types.identifier(key), value);
}
function method(key, body) {
return _core.types.objectMethod("method", _core.types.identifier(key), [], _core.types.blockStatement(body));
}
function takeDecorators(node) {
let result;
if (node.decorators && node.decorators.length > 0) {
result = _core.types.arrayExpression(node.decorators.map(decorator => decorator.expression));
}
node.decorators = undefined;
return result;
}
function getKey(node) {
if (node.computed) {
return node.key;
} else if (_core.types.isIdentifier(node.key)) {
return _core.types.stringLiteral(node.key.name);
} else {
return _core.types.stringLiteral(String(node.key.value));
}
}
function extractElementDescriptor(file, classRef, superRef, path) {
const isMethod = path.isClassMethod();
if (path.isPrivate()) {
throw path.buildCodeFrameError(`Private ${isMethod ? "methods" : "fields"} in decorated classes are not supported yet.`);
}
if (path.node.type === "ClassAccessorProperty") {
throw path.buildCodeFrameError(`Accessor properties are not supported in 2018-09 decorator transform, please specify { "version": "2021-12" } instead.`);
}
if (path.node.type === "StaticBlock") {
throw path.buildCodeFrameError(`Static blocks are not supported in 2018-09 decorator transform, please specify { "version": "2021-12" } instead.`);
}
const {
node,
scope
} = path;
new _helperReplaceSupers.default({
methodPath: path,
objectRef: classRef,
superRef,
file,
refToPreserve: classRef
}).replace();
const properties = [prop("kind", _core.types.stringLiteral(_core.types.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && _core.types.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean);
if (_core.types.isClassMethod(node)) {
const id = node.computed ? null : node.key;
const transformed = _core.types.toExpression(node);
properties.push(prop("value", (0, _helperFunctionName.default)({
node: transformed,
id,
scope
}) || transformed));
} else if (_core.types.isClassProperty(node) && node.value) {
properties.push(method("value", _core.template.statements.ast`return ${node.value}`));
} else {
properties.push(prop("value", scope.buildUndefinedNode()));
}
path.remove();
return _core.types.objectExpression(properties);
}
function addDecorateHelper(file) {
try {
return file.addHelper("decorate");
} catch (err) {
if (err.code === "BABEL_HELPER_UNKNOWN") {
err.message += "\n '@babel/plugin-transform-decorators' in non-legacy mode" + " requires '@babel/core' version ^7.0.2 and you appear to be using" + " an older version.";
}
throw err;
}
}
function buildDecoratedClass(ref, path, elements, file) {
const {
node,
scope
} = path;
const initializeId = scope.generateUidIdentifier("initialize");
const isDeclaration = node.id && path.isDeclaration();
const isStrict = path.isInStrictMode();
const {
superClass
} = node;
node.type = "ClassDeclaration";
if (!node.id) node.id = _core.types.cloneNode(ref);
let superId;
if (superClass) {
superId = scope.generateUidIdentifierBasedOnNode(node.superClass, "super");
node.superClass = superId;
}
const classDecorators = takeDecorators(node);
const definitions = _core.types.arrayExpression(elements.filter(element => !element.node.abstract && element.node.type !== "TSIndexSignature").map(path => extractElementDescriptor(file, node.id, superId, path)));
const wrapperCall = _core.template.expression.ast`
${addDecorateHelper(file)}(
${classDecorators || _core.types.nullLiteral()},
function (${initializeId}, ${superClass ? _core.types.cloneNode(superId) : null}) {
${node}
return { F: ${_core.types.cloneNode(node.id)}, d: ${definitions} };
},
${superClass}
)
`;
if (!isStrict) {
wrapperCall.arguments[1].body.directives.push(_core.types.directive(_core.types.directiveLiteral("use strict")));
}
let replacement = wrapperCall;
let classPathDesc = "arguments.1.body.body.0";
if (isDeclaration) {
replacement = _core.template.statement.ast`let ${ref} = ${wrapperCall}`;
classPathDesc = "declarations.0.init." + classPathDesc;
}
return {
instanceNodes: [_core.template.statement.ast`${_core.types.cloneNode(initializeId)}(this)`],
wrapClass(path) {
path.replaceWith(replacement);
return path.get(classPathDesc);
}
};
}
\ No newline at end of file
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