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

lingui extract babel config doesn't support experimental syntax 'decoratorAutoAccessors' #2057

Closed
1 of 3 tasks
lscheibel opened this issue Oct 18, 2024 · 1 comment · Fixed by #2058
Closed
1 of 3 tasks

Comments

@lscheibel
Copy link

lscheibel commented Oct 18, 2024

Describe the bug
When running lingui extract in a codebase that uses decoratorAutoAccessors, babel will throw a Syntax Error: Support for the experimental syntax 'decoratorAutoAccessors' isn't currently enabled.

Babel config used during extraction:

Babel configs on "<...>.ts" (ascending priority):
programmatic options
{
  "code": false,
  "babelrc": false,
  "configFile": false,
  "filename": "<...>.ts",
  "parserOpts": {
    "plugins": [
      "importAttributes",
      "explicitResourceManagement",
      "typescript",
      "decorators-legacy"
    ]
  },
  "plugins": [
    [
      "macros",
      {
        "lingui": {
          "extract": true,
          "linguiConfig": {
            "catalogs": [
              {
                "path": "<..>/src/locales/{locale}",
                "include": [
                  "src"
                ]
              }
            ],
            "catalogsMergePath": "",
            "compileNamespace": "cjs",
            "compilerBabelOptions": {
              "minified": true,
              "jsescOption": {
                "minimal": true
              }
            },
            "extractorParserOptions": {
              "tsExperimentalDecorators": true
            },
            "fallbackLocales": {},
            "format": "po",
            "formatOptions": {
              "origins": true,
              "lineNumbers": true
            },
            "locales": [
              "en",
              "de"
            ],
            "orderBy": "messageId",
            "pseudoLocale": "",
            "rootDir": "<...>",
            "runtimeConfigModule": {
              "i18nImportModule": "@lingui/core",
              "i18nImportName": "i18n",
              "TransImportModule": "@lingui/react",
              "TransImportName": "Trans"
            },
            "sourceLocale": "",
            "service": {
              "name": "",
              "apiKey": ""
            }
          }
        }
      }
    ],
    [
      "[Function: function index({ types: t }) {\n  let localTransCom ... ]",
      {}
    ]
  ]
}
-----End Babel configs-----

To Reproduce
Steps to reproduce the behavior, possibly with minimal code sample, e.g:

class Example {
    accessor myProperty = 5;
}

Expected behavior
In my case I'd simply expect lingui extract to properly handle accessor syntax, however in the bigger picture I'd expect the extracter to parse the code with the same config that I've defined in my vite.config.ts (in this case). At the very least allowing me to specify the babel config used during extraction would already go a long way.

Additional context
Note that the decoratorAutoAccessors syntax is popular with modern MobX codebases.

  • jsLingui version lingui --version: 4.13.0
  • Babel version npm list @babel/core
<...>@0.0.0 <...>
├─┬ @babel/plugin-proposal-decorators@7.24.7
│ ├─┬ @babel/core@7.25.2
│ │ └─┬ @babel/helper-module-transforms@7.25.2
│ │   └── @babel/core@7.25.2 deduped
│ ├─┬ @babel/helper-create-class-features-plugin@7.25.0
│ │ ├── @babel/core@7.25.2 deduped
│ │ └─┬ @babel/helper-replace-supers@7.25.0
│ │   └── @babel/core@7.25.2 deduped
│ └─┬ @babel/plugin-syntax-decorators@7.24.7
│   └── @babel/core@7.25.2 deduped
├─┬ @lingui/cli@4.13.0
│ └── @babel/core@7.25.2 deduped
├─┬ @vitejs/plugin-react@4.3.1
│ ├── @babel/core@7.25.2 deduped
│ ├─┬ @babel/plugin-transform-react-jsx-self@7.24.7
│ │ └── @babel/core@7.25.2 deduped
│ └─┬ @babel/plugin-transform-react-jsx-source@7.24.1
│   └── @babel/core@7.25.2 deduped
└─┬ vite-plugin-svgr@4.2.0
  ├─┬ @svgr/core@8.1.0
  │ ├── @babel/core@7.25.2 deduped
  │ └─┬ @svgr/babel-preset@8.1.0
  │   ├── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-add-jsx-attribute@8.0.0
  │   │ └── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-remove-jsx-attribute@8.0.0
  │   │ └── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-remove-jsx-empty-expression@8.0.0
  │   │ └── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-replace-jsx-attribute-value@8.0.0
  │   │ └── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-svg-dynamic-title@8.0.0
  │   │ └── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-svg-em-dimensions@8.0.0
  │   │ └── @babel/core@7.25.2 deduped
  │   ├─┬ @svgr/babel-plugin-transform-react-native-svg@8.1.0
  │   │ └── @babel/core@7.25.2 deduped
  │   └─┬ @svgr/babel-plugin-transform-svg-component@8.0.0
  │     └── @babel/core@7.25.2 deduped
  └─┬ @svgr/plugin-jsx@8.1.0
    └── @babel/core@7.25.2 deduped
  • Macro support:
  • I'm using SWC with @lingui/swc-plugin
  • I'm using Babel with babel-macro-plugin: "babel-plugin-macros": "^3.1.0"
  • I'm not using macro
  • Your Babel config (e.g. .babelrc) or framework you use (Create React App, NextJs, Vite)
    Vite with plugin-react: react({ babel: { plugins: [['@babel/plugin-proposal-decorators', { version: '2023-11' }], 'macros'] } }),
@timofei-iatsenko
Copy link
Collaborator

@lscheibel please read the doc i wrote in the related PR #2058

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants