Skip to content

Javascript auto import of commonjs can override language keywords with exported items. #43716

@celebro

Description

@celebro
  • VS Code Version: 1.55.2 and 1.56.0-insider
  • OS Version: macOS Big Sur

Steps to Reproduce:

  1. Create a commonjs file that (default) exports an object with a property name that is a language keyword, and keep the file open in a tab (or enable javascript type checking for the project instead of keeping the tab open), e.g.
const consts = {
    'break': 'break',
};

module.exports = consts;
  1. Create another file, in which the keyword that is also a property on the exported object from previous step will be used (but don't add the keyword yet), save the file and close it, e.g.
for (let v of []) {
    
}
  1. Open the file from previous step, and add the keyword and the semicolon, e.g. break;. VS Code automatically adds the require statement, e.g. const { break } = require("./consts");, creating a syntax error with the keyword. This is the auto import feature controlled by the javascript.suggest.autoImports setting.

Does this issue occur when all extensions are disabled?: Yes

vscode-autoimport.mp4

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions