Skip to content

The VariableDeclaration with declare has wrong SyntaxContext #9892

@CPunisher

Description

@CPunisher

Describe the bug

In the following code, the two as in the code should have same SyntaxContext like two bs. But the actual behavior is:

declare const a#0: number
var b#2 = 1
export { a#1, b#2  }

which breaks emitIsolatedDts.

I think this is introduced by #9734.

Input code

declare const a: number
var b = 1
export { a, b  }

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "experimental": {
        "emitIsolatedDts": true
    },
    "target": "es2022",
  },
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.7&code=H4sIAAAAAAAAA0tJTc5JLEpVSM7PKy5RSLRSyCvNTUot4ipLLFJIUrBVMORKrSjILypRqFZI1AGKKNQCANOlQGQyAAAA&config=H4sIAAAAAAAAA1WNsQ6DMAxE935F5LlDlbEzC59hgVsFhTayrxII8e91QEVl872n8y2XEGiwju5h8dNDYTXRIzux%2BQWenBDmItZpKqDrz8KqenA22dC6G5KpiKZRvJv%2FvlUzJrT2zgzpG5hL6OdcButTUCfF4i3Gbc7l%2BgWV6P%2BGsAAAAA%3D%3D

SWC Info output

No response

Expected behavior

declare const a: number;
declare var b: number;
export { a, b };

Actual behavior

declare var b: number;
export { a, b };

Version

1.10.7

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions