簡體   English   中英

尚不支持計算方法/屬性裝飾器

[英]Computed method/property decorators are not yet supported

我有錯誤

    SyntaxError: /Users/myproject/src/libts/antlr4ts/misc/Array2DHashSet.ts: Computed method/property decorators are not yet supported.
      23 | const LOAD_FACTOR: number = 0.75;
      24 |
    > 25 | export class Array2DHashSet<T extends { toString(): string; }> implements JavaSet<T> {
         |        ^
      26 |      @NotNull
      27 |      protected comparator: EqualityComparator<T>;

my.babelrc.json 是

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "node": "current"
                }
            }
        ],
        "@babel/preset-typescript"
    ],
    "plugins": [
        [
            "@babel/plugin-proposal-decorators",
            {
                "legacy": true
            }
        ],
        [
            "@babel/plugin-syntax-decorators",
            {
                "legacy": true
            }
        ],
        [
            "@babel/plugin-proposal-class-properties",
            {
                "loose": true
            }
        ],
        "babel-plugin-parameter-decorator",
        [
            "@babel/plugin-transform-destructuring",
            {
                "useBuiltIns": true
            }
        ],
        "@babel/plugin-transform-runtime"
    ],
    "env": {
        "test": {
            "plugins": [
                [
                    "@babel/plugin-proposal-decorators",
                    {
                        "legacy": true
                    }
                ],
                [
                    "@babel/plugin-syntax-decorators",
                    {
                        "legacy": true
                    }
                ],
                [
                    "@babel/plugin-proposal-class-properties",
                    {
                        "loose": true
                    }
                ],
                "babel-plugin-parameter-decorator",
                [
                    "@babel/plugin-transform-destructuring",
                    {
                        "useBuiltIns": true
                    }
                ],
                "@babel/plugin-transform-runtime"
            ],
            "presets": [
                [
                    "@babel/preset-env",
                    {
                        "targets": {
                            "node": "current"
                        }
                    }
                ],
                "@babel/preset-typescript"
            ]
        }
    }
}

我正在將https://github.com/tunnelvisionlabs/antlr4ts中的代碼復制到我的存儲庫中以進行嘗試。 但是當我運行jz test時,出現了上述錯誤。 看來我需要使用 babel 插件來編譯 antlr4ts 源代碼。 但我有很多錯誤。 目前,我收到上述錯誤。 缺少任何 babel 配置或設置嗎? 謝謝

錯誤位置不對。 @NotNull裝飾器可能是個問題。 要進行此編譯,您必須在 tsconfig.json 文件中啟用實驗性裝飾器:

{
    "compilerOptions": {
        "experimentalDecorators": true,
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM