Transformation of static blocks breaks existing code

オープン
#31,674 コメント 8 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
angular, babel, typescript, webpack
領域
build-system, cli

調査の方向性

リンクされている angular-monaco-repro リポジトリから開始し、Webpack builder を通じて @babel/plugin-transform-class-static-block 7.27.1 と 7.28.3 を使用したビルドを比較します。プラグインが Angular CLI のビルドに入る箇所を追跡し、その後、現在のプラグインバージョンで生成された CodeEditorWidget が報告された super-constructor エラーをもうスローしないことを確認します。

索引モデルが issue の本文から書いたものです。

説明

area: @angular/build freq1: low needs: investigation severity5: regression type: bug/fix
Command

build

Is this a regression?
  • Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was

No response

Description

It appears that when Angular compiles using a recent version of Babel's plugin-transform-class-static-block, with the Webpack builder, the output is transformed in such a way it breaks existing code.

Angular code compiled and bundled with @babel/plugin-transform-class-static-block@7.27.1:

let CodeEditorWidget = class CodeEditorWidget extends _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_5__.Disposable {
  static #_ = CodeEditorWidget_1 = this;
  static #_2 = this.dropIntoEditorDecorationOptions = _common_model_textModel_js__WEBPACK_IMPORTED_MODULE_27__.ModelDecorationOptions.register({
    description: 'workbench-dnd-target',
    className: 'dnd-target'
  }); //#endregion
  get isSimpleWidget() {
    return this._configuration.isSimpleWidget;
  }
  get contextMenuId() {
    return this._configuration.contextMenuId;
  }
  constructor(domElement, _options, codeEditorWidgetOptions, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService) {
    var _this;
    super();
    _this = this;

   // Omitted for brevity
};

Angular code compiled and bundled with @babel/plugin-transform-class-static-block@7.28.3:

let CodeEditorWidget = (class CodeEditorWidget extends _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_5__.Disposable {                 
  //#endregion
  get isSimpleWidget() {
    return this._configuration.isSimpleWidget;
  }
  get contextMenuId() {
    return this._configuration.contextMenuId;
  }
  constructor(domElement, _options, codeEditorWidgetOptions, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService, languageConfigurationService, languageFeaturesService) {
    var _this = this;
    super();

    // Omitted for brevity

  static #_ = _staticBlock = () => (CodeEditorWidget_1 = this, this.dropIntoEditorDecorationOptions = _common_model_textModel_js__WEBPACK_IMPORTED_MODULE_27__.ModelDecorationOptions.register({
    description: 'workbench-dnd-target',
    className: 'dnd-target'
  }), this);
}, _staticBlock());

The workaround, which you will also see explained in the attached reproducer, is to override the version of the Babel's plugin to 7.27.1.

I don't understand why, and under which circumstance, that plugin is injected into the compilation process.

Minimal Reproduction

Steps to reproduce can be found on the reproducer's repository: https://github.com/lppedd/angular-monaco-repro

Exception or Error
ERROR ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
  at new CodeEditorWidget (codeEditorWidget.js:69:252)
  at new StandaloneCodeEditor (standaloneCodeEditor.js:69:9)
  at new StandaloneEditor (standaloneCodeEditor.js:188:9)
  at InstantiationService._createInstance (instantiationService.js:130:24)
  at InstantiationService.createInstance (instantiationService.js:101:27)
  at Object.create (standaloneEditor.js:43:33)
  at App.ngAfterViewInit (app.ts:16:33)
  at callHookInternal (debug_node.mjs:860:14)
  at callHook (debug_node.mjs:887:13)
  at callHooks (debug_node.mjs:841:17)
Your Environment
Angular CLI: 20.3.8
Node: 22.18.0
Package Manager: npm 11.6.2
OS: win32 x64
    

Angular: 20.3.9
... common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                         Version
---------------------------------------
@angular-devkit/architect       0.2003.8
@angular-devkit/build-angular   20.3.8
@angular-devkit/core            20.3.8
@angular-devkit/schematics      20.3.8
@angular/build                  20.3.8
@angular/cli                    20.3.8
@schematics/angular             20.3.8
rxjs                            7.8.2
typescript                      5.9.3
zone.js                         0.15.1
Anything else relevant?

No response

主要言語
TypeScript
スター
27k
フォーク
11.8k
平均マージ
16時間 35分
マージ済み PR(30日)
176

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

angular/angular-cli のほかの issue

angular/angular-cli の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。