@ts-bridge/cli
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -10,2 +10,10 @@ # Changelog | ||
## [0.4.1] | ||
### Fixed | ||
- Re-use existing default import for importing undetected named imports ([#40](https://github.com/ts-bridge/ts-bridge/pull/40)) | ||
- This fixes a bug where the default import was not properly replaced, | ||
resulting in undefined variables. | ||
## [0.4.0] | ||
@@ -99,3 +107,4 @@ | ||
[Unreleased]: https://github.com/ts-bridge/ts-bridge/compare/@ts-bridge/cli@0.4.0...HEAD | ||
[Unreleased]: https://github.com/ts-bridge/ts-bridge/compare/@ts-bridge/cli@0.4.1...HEAD | ||
[0.4.1]: https://github.com/ts-bridge/ts-bridge/compare/@ts-bridge/cli@0.4.0...@ts-bridge/cli@0.4.1 | ||
[0.4.0]: https://github.com/ts-bridge/ts-bridge/compare/@ts-bridge/cli@0.3.0...@ts-bridge/cli@0.4.0 | ||
@@ -102,0 +111,0 @@ [0.3.0]: https://github.com/ts-bridge/ts-bridge/compare/@ts-bridge/cli@0.2.0...@ts-bridge/cli@0.3.0 |
@@ -134,3 +134,7 @@ import typescript from 'typescript'; | ||
const moduleSpecifier = getIdentifierName(node.moduleSpecifier.text); | ||
const importIdentifier = getUniqueIdentifier(typeChecker, sourceFile, moduleSpecifier); | ||
const importIdentifier = | ||
// If the import declaration has a name (default import), use that name, to | ||
// avoid breaking the default import transformer. | ||
node.importClause.name?.text ?? | ||
getUniqueIdentifier(typeChecker, sourceFile, moduleSpecifier); | ||
const statements = []; | ||
@@ -137,0 +141,0 @@ if (importNames.detected.length > 0) { |
@@ -592,2 +592,16 @@ import { getFixture } from '@ts-bridge/test-utils'; | ||
}); | ||
it('only rewrites default imports in combined imports', async () => { | ||
expect(files['combined-imports.js']).toMatchInlineSnapshot(` | ||
"function $importDefault(module) { | ||
if (module?.__esModule) { | ||
return module.default; | ||
} | ||
return module; | ||
} | ||
import $foo, { foo as bar } from 'commonjs-module'; | ||
const foo = $importDefault($foo); | ||
console.log(foo, bar); | ||
" | ||
`); | ||
}); | ||
it('does not rewrite an invalid import', async () => { | ||
@@ -655,2 +669,23 @@ expect(files['invalid.js']).toMatchInlineSnapshot(` | ||
}); | ||
it('uses an existing default import if it exists', () => { | ||
expect(files['combined-imports.js']).toMatchInlineSnapshot(` | ||
"import $foo from 'commonjs-module'; | ||
const { bar } = $foo; | ||
/** | ||
* Default import helper. | ||
* | ||
* @param module - Module with default export. | ||
* @returns Default export. | ||
*/ | ||
function $importDefault(module) { | ||
if (module?.__esModule) { | ||
return module.default; | ||
} | ||
return module; | ||
} | ||
const foo = $importDefault($foo); | ||
console.log(foo, bar); | ||
" | ||
`); | ||
}); | ||
it('does not rewrite a named import for a detected CommonJS module import', async () => { | ||
@@ -657,0 +692,0 @@ expect(files['detected.js']).toMatchInlineSnapshot(` |
{ | ||
"name": "@ts-bridge/cli", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Bridge the gap between ES modules and CommonJS modules with an easy-to-use alternative to `tsc`.", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@ts-bridge/resolver": "^0.1.0", | ||
"@ts-bridge/resolver": "^0.1.1", | ||
"chalk": "^5.3.0", | ||
@@ -51,0 +51,0 @@ "cjs-module-lexer": "^1.3.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296335
6585
Updated@ts-bridge/resolver@^0.1.1