Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use loose mode for plugin-proposal-optional-chaining to generate less code. #82

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .api/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "@cocos/ccbuild" {

Check warning on line 1 in .api/public.d.ts

View workflow job for this annotation

GitHub Actions / test

File ignored by default.
/**
* @group Merged Types
*/
Expand Down Expand Up @@ -5822,6 +5822,7 @@
opts?: __private.___node_modules_cocos_babel_plugin_dynamic_import_vars_lib_index__Options;
}>;
export const transformModulesSystemjs: any;
export const proposalOptionalChaining: any;
}
export namespace helpers {
export function addDefault(path: traverse.NodePath, importedSource: string, opts?: Partial<ImportOptions>): core.types.Identifier;
Expand Down
5 changes: 5 additions & 0 deletions modules/build-engine/src/engine-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import babel = Transformer.core;
import babelPresetEnvOptions = Transformer.presets.presetEnv.Options;
import babelPluginTransformForOf = Transformer.plugins.transformForOf;
import babelPluginProposalOptionalChaining = Transformer.plugins.proposalOptionalChaining;
import babelPresetEnv = Transformer.presets.presetEnv;
import babelPluginDynamicImportVars = Transformer.plugins.cocosDynamicImportVars;
import babelPresetCC = Transformer.presets.presetCC.babelPresetCC;
Expand Down Expand Up @@ -185,6 +186,10 @@
}]);
}

babelPlugins.push([babelPluginProposalOptionalChaining, {
loose: true,
}]);

babelPlugins.push(
[babelPluginDynamicImportVars, {
resolve: {
Expand Down Expand Up @@ -261,7 +266,7 @@

{
name: '@cocos/ccbuild|module-overrides',
resolveId(source, importer): string | null {

Check warning on line 269 in modules/build-engine/src/engine-js/index.ts

View workflow job for this annotation

GitHub Actions / test

'importer' is defined but never used
if (moduleOverrides[source]) {
return source;
} else {
Expand Down
1 change: 1 addition & 0 deletions modules/transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@babel/plugin-syntax-typescript": "^7.20.0",
"@babel/plugin-transform-for-of": "^7.21.0",
"@babel/plugin-transform-modules-systemjs": "~7.22.5",
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
"@babel/preset-env": "^7.20.2",
"@babel/traverse": "^7.20.13",
"@cocos/babel-plugin-dynamic-import-vars": "^1.0.2",
Expand Down
2 changes: 2 additions & 0 deletions modules/transformer/src/babel/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import syntaxDecorators from '@babel/plugin-syntax-decorators';
import transformForOf from '@babel/plugin-transform-for-of';
import cocosDynamicImportVars from '@cocos/babel-plugin-dynamic-import-vars';
import transformModulesSystemjs from '@babel/plugin-transform-modules-systemjs';
import proposalOptionalChaining from '@babel/plugin-proposal-optional-chaining';

export {
syntaxTS,
syntaxDecorators,
transformForOf,
cocosDynamicImportVars,
transformModulesSystemjs,
proposalOptionalChaining,
};
5 changes: 5 additions & 0 deletions modules/transformer/static/types-polyfill.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// add module declaration for some babel plugins

declare module '@babel/plugin-syntax-typescript' {
const $: any;

Check warning on line 4 in modules/transformer/static/types-polyfill.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
export default $;
}
declare module '@babel/plugin-syntax-decorators' {
const $: any;

Check warning on line 8 in modules/transformer/static/types-polyfill.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
export default $;
}
declare module '@babel/plugin-transform-for-of' {
const $: any;

Check warning on line 12 in modules/transformer/static/types-polyfill.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
export default $;
}
declare module '@babel/plugin-transform-modules-systemjs' {
const $: any;

Check warning on line 16 in modules/transformer/static/types-polyfill.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
export default $;
}

declare module '@babel/plugin-proposal-optional-chaining' {
const $: any;

Check warning on line 21 in modules/transformer/static/types-polyfill.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
export default $;
}
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cocos/ccbuild",
"version": "2.3.7",
"version": "2.3.8",
"description": "The next generation of build tool for Cocos engine.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions test/build-engine/__snapshots__/engine-js.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -943,27 +943,27 @@ class MangleQuestionProperties {
}
test() {
var _this$_ccprivate$_myP, _this$_ccprivate$_myP2, _this$_ccprivate$_myP3;
if ((_this$_ccprivate$_myP = this._ccprivate$_myProp) !== null && _this$_ccprivate$_myP !== void 0 && _this$_ccprivate$_myP._ccprivate$mangleMeQuestionProp) {
if ((_this$_ccprivate$_myP = this._ccprivate$_myProp) != null && _this$_ccprivate$_myP._ccprivate$mangleMeQuestionProp) {
this._ccprivate$_myProp._ccprivate$mangleMeQuestionProp = 123;
}
const a = (_this$_ccprivate$_myP2 = this._ccprivate$_myProp) === null || _this$_ccprivate$_myP2 === void 0 ? void 0 : _this$_ccprivate$_myP2._ccprivate$mangleMeQuestionProp;
const a = (_this$_ccprivate$_myP2 = this._ccprivate$_myProp) == null ? void 0 : _this$_ccprivate$_myP2._ccprivate$mangleMeQuestionProp;
console.log(a);
console.log((_this$_ccprivate$_myP3 = this._ccprivate$_myProp) === null || _this$_ccprivate$_myP3 === void 0 ? void 0 : _this$_ccprivate$_myP3['mangleMeQuestionProp']);
console.log((_this$_ccprivate$_myP3 = this._ccprivate$_myProp) == null ? void 0 : _this$_ccprivate$_myP3['mangleMeQuestionProp']);
if (this._ccprivate$_myProp) {
console.log(this._ccprivate$_myProp["_ccprivate$mangleMeQuestionProp"]);
}
}
getProp() {
var _this$_ccprivate$_myP4;
return (_this$_ccprivate$_myP4 = this._ccprivate$_myProp) === null || _this$_ccprivate$_myP4 === void 0 ? void 0 : _this$_ccprivate$_myP4._ccprivate$mangleMeQuestionProp;
return (_this$_ccprivate$_myP4 = this._ccprivate$_myProp) == null ? void 0 : _this$_ccprivate$_myP4._ccprivate$mangleMeQuestionProp;
}
getProp2() {
var _this$_ccprivate$_myP5;
return (_this$_ccprivate$_myP5 = this._ccprivate$_myProp) === null || _this$_ccprivate$_myP5 === void 0 ? void 0 : _this$_ccprivate$_myP5['mangleMeQuestionProp'];
return (_this$_ccprivate$_myP5 = this._ccprivate$_myProp) == null ? void 0 : _this$_ccprivate$_myP5['mangleMeQuestionProp'];
}
getProp3() {
var _this$_ccprivate$_myP6, _this$_ccprivate$_myP7, _this$_ccprivate$_myP8;
return (_this$_ccprivate$_myP6 = this._ccprivate$_myProp) === null || _this$_ccprivate$_myP6 === void 0 ? void 0 : (_this$_ccprivate$_myP7 = _this$_ccprivate$_myP6._ccprivate$prop2) === null || _this$_ccprivate$_myP7 === void 0 ? void 0 : (_this$_ccprivate$_myP8 = _this$_ccprivate$_myP7._ccprivate$aaa) === null || _this$_ccprivate$_myP8 === void 0 ? void 0 : _this$_ccprivate$_myP8._ccprivate$bbb;
return (_this$_ccprivate$_myP6 = this._ccprivate$_myProp) == null ? void 0 : (_this$_ccprivate$_myP7 = _this$_ccprivate$_myP6._ccprivate$prop2) == null ? void 0 : (_this$_ccprivate$_myP8 = _this$_ccprivate$_myP7._ccprivate$aaa) == null ? void 0 : _this$_ccprivate$_myP8._ccprivate$bbb;
}
}
const mangleQuestionProperties = new MangleQuestionProperties();
Expand Down
Loading