Skip to content

ts.getPreProcessedFileInfo doesn't detect imported files from import(template) and require(tempalte) #33680

@IllusionMH

Description

@IllusionMH

TypeScript Version: 3.6.3, 3.7.0-dev.20190928

Search Terms:

Code

const ts = require('typescript');

const lines = [
    'const rs = require("rs.ts");',
    'const rt = require(`rt.ts`);',
    'const is = import("is.ts");',
    'const it = import(`it.ts`);',
].join('\n')

console.log(ts.preProcessFile(lines, true, true));

Expected behavior:

{
    referencedFiles: [],
    typeReferenceDirectives: [],
    libReferenceDirectives: [],
    importedFiles: [
        { fileName: 'rs.ts', pos: 19, end: 24 },
        { fileName: 'rt.ts', pos: 48, end: 53 },
        { fileName: 'is.ts', pos: 76, end: 81 },
        { fileName: 'it.ts', pos: 104, end: 109 }
    ],
    isLibFile: false,
    ambientExternalModules: undefined
}

Actual behavior:

{
    referencedFiles: [],
    typeReferenceDirectives: [],
    libReferenceDirectives: [],
    importedFiles: [
        { fileName: 'rs.ts', pos: 19, end: 24 },
        { fileName: 'is.ts', pos: 76, end: 81 }
    ],
    isLibFile: false,
    ambientExternalModules: undefined
}

Because src/services/preProcess.ts only checks for StringLiteral's bun not for NoSubstitutionTemplateLiteral's which were allowed there for a long time.

Playground Link: N/A

Related Issues: found during implementing #32064 , but this syntax and type checked worked long before this PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions