Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
213146d
Integrate importStar and importDefault helpers
weswigham Nov 1, 2017
b5a7ef9
Accept baselines
weswigham Nov 1, 2017
8abc907
Support dynamic imports, write helpers for umd module (and amd is pos…
weswigham Nov 1, 2017
2d0c8d3
Accept baselines
weswigham Nov 1, 2017
a725916
Support AMD, use same helper initialization as is normal
weswigham Nov 2, 2017
e910603
update typechecker to have errors on called imported namespaces and g…
weswigham Nov 2, 2017
e84b051
Overhaul allowSyntheticDefaultExports to be safer
weswigham Nov 3, 2017
f23d41c
Put the new behavior behind a flag
weswigham Nov 3, 2017
ebd4c03
Merge branch 'master' into module-nodejs
weswigham Nov 7, 2017
3b33df0
Rename strictESM to ESMInterop
weswigham Nov 7, 2017
7ff11bb
Merge branch 'master' into module-nodejs
weswigham Nov 10, 2017
bcafdba
ESMInterop -> ESModuleInterop, make default for tsc --init
weswigham Nov 10, 2017
eaf2fc5
Merge branch 'master' into module-nodejs
weswigham Nov 17, 2017
29c731c
Rename ESMInterop -> ESModuleInterop in module.ts, add emit test (sin…
weswigham Nov 17, 2017
4350caf
Merge branch 'master' into module-nodejs
weswigham Nov 17, 2017
e20a548
Remove erroneous semicolons from helper
weswigham Nov 18, 2017
578141d
Merge branch 'master' into module-nodejs
weswigham Nov 28, 2017
dfe5675
Reword diagnostic
weswigham Nov 29, 2017
8c6c313
Change style
weswigham Nov 29, 2017
3d996d7
Edit followup diagnostic
weswigham Nov 29, 2017
2f9c240
Add secondary quickfix for call sites, tests forthcoming
weswigham Nov 29, 2017
2361f37
Add synth default to namespace import type, enhance quickfix
weswigham Nov 29, 2017
357996b
Pair of spare tests for good measure
weswigham Nov 29, 2017
a682476
Merge branch 'master' into module-nodejs
weswigham Dec 18, 2017
6e9e874
Fix typos in diagnostic message
weswigham Jan 5, 2018
a654b82
Improve comment clarity
weswigham Jan 5, 2018
ef6faf1
Actually accept the updated changes to the esmodule interop description
weswigham Jan 8, 2018
a8233b3
ESModule -> esModule
weswigham Jan 8, 2018
f4f4e84
Use find and not forEach
weswigham Jan 8, 2018
386c54d
Use guard
weswigham Jan 8, 2018
2663db7
Rely on implicit falsiness of Result.False
weswigham Jan 8, 2018
8068e2e
These should have been emit flags
weswigham Jan 8, 2018
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
Prev Previous commit
Next Next commit
update typechecker to have errors on called imported namespaces and g…
…ood error recovery with a quickfix
  • Loading branch information
weswigham committed Nov 3, 2017
commit e9106036e5f087c9f8580f436b2bade891110142
67 changes: 61 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,34 @@ namespace ts {
// combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression, dontResolveAlias: boolean): Symbol {
const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias);
if (!dontResolveAlias && symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
if (!dontResolveAlias && symbol) {
if (!(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
return symbol;
}
const referenaceParent = moduleReferenceExpression.parent;
if (referenaceParent.kind === SyntaxKind.ImportDeclaration && getNamespaceDeclarationNode(referenaceParent as ImportDeclaration)) {
const type = getTypeOfSymbol(symbol);
let sigs = getSignaturesOfStructuredType(type, SignatureKind.Call);
if (!sigs || !sigs.length) {
sigs = getSignaturesOfStructuredType(type, SignatureKind.Construct);
}
if (sigs && sigs.length) {
// Create a new symbol which has the module's type less the call and construct signatures
const result = createSymbol(symbol.flags, symbol.escapedName);
result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
result.parent = symbol.parent;
result.target = symbol;
result.originatingImport = referenaceParent as ImportDeclaration;
if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration;
if (symbol.constEnumOnlyModule) result.constEnumOnlyModule = true;
if (symbol.members) result.members = cloneMap(symbol.members);
if (symbol.exports) result.exports = cloneMap(symbol.exports);
const moduleType = resolveStructuredTypeMembers(type as StructuredType); // Should already be resolved from the signature checks above
result.type = createAnonymousType(result, moduleType.members, emptyArray, emptyArray, moduleType.stringIndexInfo, moduleType.numberIndexInfo);
return result;
}
}
}
return symbol;
}
Expand Down Expand Up @@ -8963,7 +8989,19 @@ namespace ts {

diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
}
return result !== Ternary.False;
const answer = result !== Ternary.False;
// Check if we should issue an extra diagnostic to produce a quickfix for a slightly incorrect import statement
if (headMessage && errorNode && !answer && source.symbol) {
const links = getSymbolLinks(source.symbol);
if (links.originatingImport) {
const helpfulRetry = checkTypeRelatedTo(getTypeOfSymbol(links.target), target, relation, /*errorNode*/ undefined);
if (helpfulRetry) {
// Likely an incorrect import. Issue a helpful diagnostic to produce a quickfix to change the import
diagnostics.add(createDiagnosticForNode(links.originatingImport, Diagnostics.Import_is_called_or_constructed_which_is_not_valid_ES2015_module_usage_and_will_fail_at_runtime));
}
}
}
return answer;

function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void {
Debug.assert(!!errorNode);
Expand Down Expand Up @@ -16618,7 +16656,7 @@ namespace ts {
error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
}
else {
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType));
invocationError(node, apparentType, SignatureKind.Call);
}
return resolveErrorCall(node);
}
Expand Down Expand Up @@ -16720,7 +16758,7 @@ namespace ts {
return signature;
}

error(node, Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature);
invocationError(node, expressionType, SignatureKind.Construct);
return resolveErrorCall(node);
}

Expand Down Expand Up @@ -16767,6 +16805,22 @@ namespace ts {
return true;
}

function invocationError(node: Node, apparentType: Type, kind: SignatureKind) {
error(node, kind === SignatureKind.Call
? Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures
: Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature
, typeToString(apparentType));
invocationErrorRecovery(apparentType, kind);
}

function invocationErrorRecovery(apparentType: Type, kind: SignatureKind) {
if (apparentType.symbol && getSymbolLinks(apparentType.symbol).originatingImport) {
const sigs = getSignaturesOfType(getTypeOfSymbol(getSymbolLinks(apparentType.symbol).target), kind);
if (!sigs || !sigs.length) return;
error(getSymbolLinks(apparentType.symbol).originatingImport, Diagnostics.Import_is_called_or_constructed_which_is_not_valid_ES2015_module_usage_and_will_fail_at_runtime);
}
}

function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[]): Signature {
const tagType = checkExpression(node.tag);
const apparentType = getApparentType(tagType);
Expand All @@ -16784,7 +16838,7 @@ namespace ts {
}

if (!callSignatures.length) {
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType));
invocationError(node, apparentType, SignatureKind.Call);
return resolveErrorCall(node);
}

Expand Down Expand Up @@ -16841,6 +16895,7 @@ namespace ts {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType));
errorInfo = chainDiagnosticMessages(errorInfo, headMessage);
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo));
invocationErrorRecovery(apparentType, SignatureKind.Call);
return resolveErrorCall(node);
}

Expand Down
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3326,6 +3326,10 @@
"category": "Message",
"code": 6186
},
"Import is called or constructed, which is not valid ES2015 module usage, and will fail at runtime.": {
"category": "Error",
"code": 7004
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down Expand Up @@ -3797,5 +3801,9 @@
"Convert to default import": {
"category": "Message",
"code": 95013
},
"Replace import with '{0}'.": {
"category": "Message",
"code": 95014
}
}
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,7 @@ namespace ts {
bindingElement?: BindingElement; // Binding element associated with property symbol
exportsSomeValue?: boolean; // True if module exports some value (not just types)
enumKind?: EnumKind; // Enum declaration classification
originatingImport?: ImportDeclaration; // Import declaration which produced the symbol, present if the symbol is poisoned
}

/* @internal */
Expand Down
52 changes: 52 additions & 0 deletions src/services/codefixes/fixInvalidImportSyntax.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* @internal */
namespace ts.codefix {
registerCodeFix({
errorCodes: [Diagnostics.Import_is_called_or_constructed_which_is_not_valid_ES2015_module_usage_and_will_fail_at_runtime.code],
getCodeActions: getActionsForInvalidImport
});

function getActionsForInvalidImport(context: CodeFixContext): CodeAction[] | undefined {
const sourceFile = context.sourceFile;

// This is the whole import statement, eg:
// import * as Bluebird from 'bluebird';
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false).parent as ImportDeclaration;
const namespace = getNamespaceDeclarationNode(node) as NamespaceImport;
const opts = context.program.getCompilerOptions();
const variations: CodeAction[] = [];
if (opts.module === ModuleKind.CommonJS || (!opts.module && opts.target < ScriptTarget.ES2015)) {
// import Bluebird = require("bluebird");
const replacement = createImportEqualsDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
namespace.name,
createExternalModuleReference(node.moduleSpecifier)
);
const changeTracker = textChanges.ChangeTracker.fromContext(context);
changeTracker.replaceNode(sourceFile, node, replacement, { useNonAdjustedEndPosition: true });
const changes = changeTracker.getChanges();
variations.push({
description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Replace_import_with_0), [changes[0].textChanges[0].newText]),
changes
});
}

// import Bluebird from "bluebird";
const replacement = createImportDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
createImportClause(namespace.name, /*namedBindings*/ undefined),
node.moduleSpecifier
);
const changeTracker = textChanges.ChangeTracker.fromContext(context);
changeTracker.replaceNode(sourceFile, node, replacement, { useNonAdjustedEndPosition: true });
const changes = changeTracker.getChanges();
variations.push({
description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Replace_import_with_0), [changes[0].textChanges[0].newText]),
changes
});

return variations;
}
}
2 changes: 2 additions & 0 deletions src/services/codefixes/fixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
/// <reference path='disableJsDiagnostics.ts' />
/// <reference path='helpers.ts' />
/// <reference path='inferFromUsage.ts' />
/// <reference path="fixInvalidImportSyntax.ts" />

2 changes: 1 addition & 1 deletion tests/baselines/reference/augmentExportEquals7.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export = lib;

=== /node_modules/@types/lib-extender/index.d.ts ===
import * as lib from "lib";
>lib : () => void
>lib : {}

declare module "lib" {
export function fn(): void;
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/es6ExportEqualsInterop.types
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ import * as y7 from "function";
>y7 : () => any

import * as y8 from "function-module";
>y8 : typeof z8
>y8 : typeof y8

import * as y9 from "class";
>y9 : typeof z9

import * as y0 from "class-module";
>y0 : typeof z0
>y0 : typeof y0

y1.a;
>y1.a : any
Expand Down Expand Up @@ -181,7 +181,7 @@ y7.a;

y8.a;
>y8.a : number
>y8 : typeof z8
>y8 : typeof y8
>a : number

y9.a;
Expand All @@ -191,7 +191,7 @@ y9.a;

y0.a;
>y0.a : number
>y0 : typeof z0
>y0 : typeof y0
>a : number

// named import
Expand Down
Loading