Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ namespace ts {
}

function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage, isForAugmentation = false): Symbol {
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral && moduleReferenceExpression.kind !== SyntaxKind.NoSubstitutionTemplateLiteral) {
return;
}

Expand Down
27 changes: 17 additions & 10 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1404,17 +1404,24 @@ namespace ts {

/**
* Returns true if the node is a CallExpression to the identifier 'require' with
* exactly one argument.
* exactly one argument (of the form 'require("name")').
* This function does not test if the node is in a JavaScript file or not.
*/
export function isRequireCall(expression: Node, checkArgumentIsStringLiteral: boolean): expression is CallExpression {
// of the form 'require("name")'
const isRequire = expression.kind === SyntaxKind.CallExpression &&
(<CallExpression>expression).expression.kind === SyntaxKind.Identifier &&
(<Identifier>(<CallExpression>expression).expression).text === "require" &&
(<CallExpression>expression).arguments.length === 1;

return isRequire && (!checkArgumentIsStringLiteral || (<CallExpression>expression).arguments[0].kind === SyntaxKind.StringLiteral);
*/
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteral: boolean): callExpression is CallExpression {
if (callExpression.kind !== SyntaxKind.CallExpression) {
return false;
}
const { expression, arguments } = callExpression as CallExpression;

if (expression.kind !== SyntaxKind.Identifier || (expression as Identifier).text !== "require") {
return false;
}

if (arguments.length !== 1) {
return false;
}
const arg = arguments[0];
return !checkArgumentIsStringLiteral || arg.kind === SyntaxKind.StringLiteral || arg.kind === SyntaxKind.NoSubstitutionTemplateLiteral;
}

export function isSingleOrDoubleQuote(charCode: number) {
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/fourslash/javaScriptModulesWithBackticks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
///<reference path="fourslash.ts" />

// @allowJs: true
// @Filename: a.js
//// exports.x = 0;

// @Filename: consumer.js
//// var a = require(`./a`);
//// a./**/;

goTo.marker();
verify.completionListContains("x");