Skip to content

Commit

Permalink
fix(ts-transform-paths): import value #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Marty Mcfly committed Nov 13, 2019
1 parent 6c1f0d5 commit 617bd33
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/ts-transform-paths/src/ImportPathInternalResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import path from 'path'
import { ImportPathsResolver } from '@zerollup/ts-helpers'
import { Config, EmitHost, TransformationContext } from './Types'

const exts = ['min.js', 'js'] as const
const jsExts = ['min.js', 'js'] as const

const tsParts = ['.ts', '.tsx', '/index.ts', '/index.tsx'] as const

export class ImportPathInternalResolver {
protected resolver: ImportPathsResolver
Expand Down Expand Up @@ -31,7 +33,7 @@ export class ImportPathInternalResolver {
if (!newImports || newImports.length === 0) return
const newImport = newImports[0]
if (this.config.tryLoadJs && emitHost && emitHost.fileExists) {
for (let ext of exts) {
for (let ext of jsExts) {
const importWithExtension = `${newImport}.${ext}`
if (emitHost.fileExists(path.join(currentDir, importWithExtension))) {
return importWithExtension
Expand All @@ -44,11 +46,9 @@ export class ImportPathInternalResolver {

const host = this.program || emitHost
if (!host) return newImport

if (
host.getSourceFile(`${newImportPath}.ts`) ||
host.getSourceFile(`${newImportPath}.tsx`)
)
return newImport
for (let part of tsParts) {
if (host.getSourceFile(`${newImportPath}${part}`)) return newImport
}
}
}

7 changes: 3 additions & 4 deletions packages/ts-transform-paths/src/importPathVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ export function importPathVisitor(
if (!node.moduleSpecifier || !ts.isStringLiteral(node.moduleSpecifier))
return
// do not use getFullText() here, bug in watch mode, https://github.com/zerkalica/zerollup/issues/12
// importValue = node.moduleSpecifier.text
importValue = stripQuotes(node.moduleSpecifier.getText(sf))
importValue = node.moduleSpecifier.text
nodeToFix = node.moduleSpecifier
} else if (
ts.isImportTypeNode(node) &&
ts.isLiteralTypeNode(node.argument) &&
ts.isStringLiteral(node.argument.literal)
) {
importValue = node.argument.literal.getText(sf)
importValue = node.argument.literal.text
} else if (ts.isModuleDeclaration(node)) {
if (!ts.isStringLiteral(node.name)) return
importValue = stripQuotes(node.name.getText(sf))
importValue = node.name.text
nodeToFix = node.name
} else {
return
Expand Down
1 change: 1 addition & 0 deletions packages/wait-all-async/__tests__/fetch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @jest-environment jsdom
import {waitAllAsync} from '../src'
import {setup, teardown, url, urlError, testObject} from './fetchHelper'

Expand Down
1 change: 1 addition & 0 deletions packages/wait-all-async/__tests__/prerender.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @jest-environment jsdom
import {createJsDomRender} from '../src'
import * as jsdom from 'jsdom'
import {setupBrowser, setup, teardown, template, url, urlError, testObject, testString} from './fetchHelper'
Expand Down
1 change: 1 addition & 0 deletions packages/wait-all-async/__tests__/react.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @jest-environment jsdom
import {createJsDomRender} from '../src'
import * as jsdom from 'jsdom'
import {setupBrowser, setup, teardown, template, url, testString, load} from './fetchHelper'
Expand Down
1 change: 1 addition & 0 deletions packages/wait-all-async/__tests__/timeout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @jest-environment jsdom
import {waitAllAsync} from '../src'

describe('timeout related', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/wait-all-async/__tests__/xhr.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @jest-environment jsdom
import {waitAllAsync} from '../src'
import {setup, teardown, url, urlError, testObject} from './fetchHelper'

Expand Down

0 comments on commit 617bd33

Please sign in to comment.