DEV: Upgrade babel & remove vendored safari-bugfix transformation (#28208)

The Safari 15 bugfix has been rolled into @babel/preset-env in the most recent version, so we no longer need to carry our vendored copy.

This commit updates @babel/preset-env, runs npx yarn-deduplicate yarn.lock, and removes the vendored transform.

This commit also refactors our theme transpiler to use @babel/preset-env, with the same list of target browsers as our ember-cli build uses. This means we no longer need to maintain a separate list of babel transforms for themes.
This commit is contained in:
David Taylor 2024-08-05 10:35:26 +01:00 committed by GitHub
parent 6d1c2a3d5a
commit 1b28b8e169
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 611 additions and 782 deletions

View File

@ -14,7 +14,7 @@
"start": "ember serve"
},
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"discourse-common": "1.0.0",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",

View File

@ -14,7 +14,7 @@
"start": "ember serve"
},
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"@uppy/aws-s3": "3.0.6",
"@uppy/aws-s3-multipart": "3.1.3",
"@uppy/core": "3.0.4",

View File

@ -8,7 +8,7 @@
"ember-addon"
],
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"deprecation-silencer": "1.0.0",
"discourse-widget-hbs": "1.0.0",
"ember-cli-babel": "^8.2.0",

View File

@ -14,7 +14,7 @@
"start": "ember serve"
},
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"ember-auto-import": "^2.7.4",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",

View File

@ -1,97 +0,0 @@
function wrapInitializer(path, babel) {
function needsWrapping(node) {
if (t.isLiteral(node) && !t.isTemplateLiteral(node)) {
return false;
}
if (
t.isCallExpression(node) ||
t.isOptionalCallExpression(node) ||
t.isNewExpression(node)
) {
return needsWrapping(node.callee) || node.arguments.some(needsWrapping);
}
if (t.isTemplateLiteral(node)) {
return node.expressions.some(needsWrapping);
}
if (t.isTaggedTemplateExpression(node)) {
return needsWrapping(node.tag) || needsWrapping(node.quasi);
}
if (t.isArrayExpression(node)) {
return node.elements.some(needsWrapping);
}
if (t.isObjectExpression(node)) {
return node.properties.some((prop) => {
if (t.isObjectProperty(prop)) {
return (
needsWrapping(prop.value) ||
(prop.computed && needsWrapping(prop.key))
);
}
if (t.isObjectMethod(prop)) {
return false;
}
return false;
});
}
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
return (
needsWrapping(node.object) ||
(node.computed && needsWrapping(node.property))
);
}
if (
t.isFunctionExpression(node) ||
t.isArrowFunctionExpression(node) ||
t.isClassExpression(node)
) {
return false;
}
if (t.isThisExpression(node)) {
return false;
}
if (t.isSequenceExpression(node)) {
return node.expressions.some(needsWrapping);
}
// Is an identifier, or anything else not covered above
return true;
}
const { types: t } = babel;
const { value } = path.node;
if (value && needsWrapping(value)) {
path.node.value = t.callExpression(
t.arrowFunctionExpression([], value),
[]
);
}
}
function makeVisitor(babel) {
return {
ClassProperty(path) {
wrapInitializer(path, babel);
},
ClassPrivateProperty(path) {
wrapInitializer(path, babel);
},
};
}
module.exports = function wrapClassFields(babel) {
return {
post(file) {
babel.traverse(file.ast, makeVisitor(babel), file.scope, this);
},
};
};

View File

@ -15,7 +15,6 @@ module.exports = function generateCommonBabelConfig() {
runEarly: true,
},
],
require.resolve("./babel-plugin-safari-class-fields-bugfix"),
],
},
};

View File

@ -37,8 +37,8 @@
"pretty-text": "1.0.0"
},
"devDependencies": {
"@babel/core": "^7.24.9",
"@babel/standalone": "^7.24.10",
"@babel/core": "^7.25.2",
"@babel/standalone": "^7.25.3",
"@colors/colors": "^1.6.0",
"@discourse/backburner.js": "^2.7.1-0",
"@discourse/itsatrap": "^2.0.10",

View File

@ -14,7 +14,7 @@
"start": "ember serve"
},
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"ember-auto-import": "^2.7.4",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",

View File

@ -14,7 +14,7 @@
"start": "ember serve"
},
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"discourse-common": "1.0.0",
"ember-auto-import": "^2.7.4",
"ember-cli-babel": "^8.2.0",

View File

@ -14,7 +14,7 @@
"start": "ember serve"
},
"dependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"ember-auto-import": "^2.7.4",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",

View File

@ -52,7 +52,7 @@ esbuild
util: "./node_modules/@zxing/text-encoding",
},
define: {
process: `{ "env": {} }`,
process: `{ "env": { "EMBER_ENV": "production" } }`,
},
external: ["fs", "path"],
entryPoints: ["./app/assets/javascripts/theme-transpiler/transpiler.js"],

View File

@ -7,7 +7,7 @@
"license": "GPL-2.0-only",
"keywords": [],
"dependencies": {
"@babel/standalone": "^7.24.10",
"@babel/standalone": "^7.25.3",
"@zxing/text-encoding": "^0.9.0",
"babel-plugin-ember-template-compilation": "^2.2.5",
"content-tag": "^2.0.1",

View File

@ -30,8 +30,8 @@ import getRandomValues from "polyfill-crypto.getrandomvalues";
import { minify as terserMinify } from "terser";
import RawHandlebars from "discourse-common/addon/lib/raw-handlebars";
import { WidgetHbsCompiler } from "discourse-widget-hbs/lib/widget-hbs-compiler";
import BabelPluginSafariClassFieldsBugfix from "../discourse/lib/babel-plugin-safari-class-fields-bugfix";
globalThis.crypto = { getRandomValues };
import { browsers } from "../discourse/config/targets";
const thisFallbackPlugin = EmberThisFallback._buildPlugin({
enableLogging: false,
@ -127,8 +127,7 @@ globalThis.compileRawTemplate = function (source, themeId) {
};
globalThis.transpile = function (source, options = {}) {
const { moduleId, filename, extension, skipModule, themeId, commonPlugins } =
options;
const { moduleId, filename, extension, skipModule, themeId } = options;
if (extension === "gjs") {
const preprocessor = new Preprocessor();
@ -140,10 +139,7 @@ globalThis.transpile = function (source, options = {}) {
if (moduleId && !skipModule) {
plugins.push(["transform-modules-amd", { noInterop: true }]);
}
commonPlugins.find((p) => p[0] === "decorator-transforms")[0] =
DecoratorTransforms;
plugins.push(...commonPlugins);
plugins.unshift(BabelPluginSafariClassFieldsBugfix);
plugins.push([DecoratorTransforms, { runEarly: true }]);
try {
return babelTransform(source, {
@ -151,6 +147,17 @@ globalThis.transpile = function (source, options = {}) {
filename,
ast: false,
plugins,
presets: [
[
"env",
{
modules: false,
targets: {
browsers,
},
},
],
],
}).code;
} catch (error) {
// Workaround for https://github.com/rubyjs/mini_racer/issues/262

View File

@ -6,15 +6,6 @@ class DiscourseJsProcessor
class TranspileError < StandardError
end
# To generate a list of babel plugins used by ember-cli, set
# babel: { debug: true } in ember-cli-build.js, then run `yarn ember build -prod`
DISCOURSE_COMMON_BABEL_PLUGINS = [
["decorator-transforms", { runEarly: true }],
"proposal-class-static-block",
"transform-parameters",
"proposal-export-namespace-from",
]
def self.ember_cli?(filename)
filename.include?("/app/assets/javascripts/discourse/dist/")
end
@ -161,7 +152,6 @@ class DiscourseJsProcessor
filename: logical_path || "unknown",
extension: extension,
themeId: theme_id,
commonPlugins: DISCOURSE_COMMON_BABEL_PLUGINS,
},
)
end

1242
yarn.lock

File diff suppressed because it is too large Load Diff