TypeScript/tests/cases/fourslash/importNameCodeFix_require_importVsRequire_addToExistingWins.ts
Andrew Branch f9945f5acf
Full support for CommonJS auto-imports in JS (#37027)
* Support add new requires

* Always use destructuring for requiring default exports

* Add more tests

* Update existing fourslash tests

* Use `getExportsAndPropertiesOfModule`

* Add UMD test

* Apply suggestions from code review

Fix typos

Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-28 14:34:20 -08:00

37 lines
859 B
TypeScript

/// <reference path="fourslash.ts" />
// If a file has both `require` and `import` declarations,
// prefer whichever can be used for an "add to existing" action.
// @allowJs: true
// @checkJs: true
// @Filename: blah.js
////export default class Blah {}
////export const Named1 = 0;
////export const Named2 = 1;
// @Filename: index.js
////var path = require('path')
//// , { promisify } = require('util')
//// , { Named1 } = require('./blah')
////
////import fs from 'fs'
////
////new Blah
goTo.file("index.js");
verify.codeFix({
index: 0,
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
description: `Add default import 'Blah' to existing import declaration from "./blah"`,
newFileContent:
`var path = require('path')
, { promisify } = require('util')
, { Named1, default: Blah } = require('./blah')
import fs from 'fs'
new Blah`
});