swc-project / swc-project/swc-node

Class with a decorated method called "export" results in a compilation error

Open
#636 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2k
Forks
95
Avg merge
14d 11h
Merged PRs (30d)
1

Description

// test.ts

function decorator(target: any, propertyName: string, descriptor: TypedPropertyDescriptor<(...args: any) => any>) {

}

class Foo {
  @decorator
  export() {
    
  }
}

Running

node -r @swc-node/register src/test.ts

This throws an error:

/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/@swc+core@1.2.122/node_modules/@swc/core/index.js:142
            throw err;
            ^

Error: error: `export` is not allowed here
 
  |
7 |   export() {
  |   ^^^^^^



Caused by:
    0: failed to process js file
    1: Syntax Error
    at Compiler.transformSync (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/@swc+core@1.2.122/node_modules/@swc/core/index.js:139:29)
    at transformSync (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/@swc+core@1.2.122/node_modules/@swc/core/index.js:223:21)
    at transformSync (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/@swc-node+core@1.8.2/node_modules/@swc-node/core/index.ts:69:26)
    at compile (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/@swc-node+register@1.4.2/node_modules/@swc-node/register/register.ts:44:40)
    at exts (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/@swc-node+register@1.4.2/node_modules/@swc-node/register/register.ts:55:31)
    at Module._compile (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/pirates@4.0.4/node_modules/pirates/lib/index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Object.newLoader [as .ts] (/Users/dmytro/Projects/work/dxos/protocols/common/temp/node_modules/.pnpm/pirates@4.0.4/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14) {
  code: 'GenericFailure'
}

tsconfig:

{
  "compilerOptions": {
    "allowJs": true,
    "composite": true,
    "incremental": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "lib": [
      "ESNext"
    ],
    "jsx": "react",
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitOverride": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "ES2018",
    "experimentalDecorators": true,
    "stripInternal": true,
  },
  "include": ["**/src/**/*.ts","**/src/**/*.tsx"],
  "exclude": ["node_modules", "dist"]
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied src/test.ts reproduction and run node -r @swc-node/register src/test.ts using the shown tsconfig. Trace how the decorated method named export is parsed, and consider the issue complete when this example compiles and runs without the reported syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.