Skip to content

Conversation

@joscha
Copy link
Contributor

@joscha joscha commented Jan 31, 2020

  • There is an associated issue in the Backlog milestone (required)
  • Code is up-to-date with the master branch
  • You've successfully run gulp runtests locally
  • There are new or updated unit tests validating the change

Fixes #33680
Complements #36143
Related to #30878

Comment on lines 89 to 95
if (lastToken === SyntaxKind.DotToken
// the following is used to prevent matches of
// `import * as doh from 'ooops';\n`;
// however this is only best-effort as it is possible to have a template
// literal ending right before, not only opening, which would prevent this
// import from being detected.
|| lastToken === SyntaxKind.NoSubstitutionTemplateLiteral) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be rolled back with #36143

Comment on lines 91 to 119
// https://github.com/microsoft/TypeScript/issues/30878#issuecomment-540698189
it.skip("Do not return reference path of imports in string literals", () => {
test("`${}`;\n`import * as doh from 'ooops';\n`;",
/*readImportFile*/ true,
/*detectJavaScriptImports*/ false,
{
referencedFiles: <ts.FileReference[]>[],
importedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
ambientExternalModules: undefined,
isLibFile: false
});
});

// https://github.com/microsoft/TypeScript/issues/30878#issue-432369315
it.skip("Correctly return statically imported files after string literals", () => {
test("`${foo}`; import './r1.ts';",
/*readImportFile*/ true,
/*detectJavaScriptImports*/ false,
{
referencedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [{ fileName: "r1.ts", pos: 17, end: 24 }],
ambientExternalModules: undefined,
isLibFile: false
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should pass with #36143


// https://github.com/microsoft/TypeScript/issues/33680#issue-500399194
it("Correctly return static imports using string literals", () => {
test("import d from `r1.ts`; import d, {a, b as B} from `r2.ts`; import d, * as NS from `r3.ts`; export {a, b as B} from `r4.ts`; export * from `r5.ts`;",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not valid JS/TS (#29318) should it be parsed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the only thing blocking the rest of the PR I am happy to roll the change back and open it in a separate request where we can then have the discussion?

Copy link
Contributor

@IllusionMH IllusionMH Jan 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how's different from #33688 with previous roll back removed string literal detection removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logically they are very similar - I don't completely understand the reason for the introduction of https://github.com/microsoft/TypeScript/pull/33688/files#diff-23f96e78fc240e5f0198a9ffef3a69e4R227; however, I believe the way I structured the tests, updated the comments and implemented the union for literal likes is more in line with the rest of the codebase. When I opened the PR unfortunately I didn't see #33688, otherwise I could have based it on top.

Copy link
Contributor

@IllusionMH IllusionMH Feb 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because import mod = require(`mod`); is error in TS String literal expected. (Spec)
They have same validation as import mod from `mod`;

@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 3, 2020
@sheetalkamat
Copy link
Member

This needs to be closed since import a from mod isn't valid syntax per ecma standards as pointed in #29318

@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

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

4 participants