mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge remote-tracking branch 'upstream/master' into fix3737
This commit is contained in:
commit
24d22da804
@ -892,7 +892,8 @@ namespace ts {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
checkStrictModeFunctionName(<FunctionExpression>node);
|
||||
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, "__function");
|
||||
let bindingName = (<FunctionExpression>node).name ? (<FunctionExpression>node).name.text : "__function";
|
||||
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, bindingName);
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
return bindClassLikeDeclaration(<ClassLikeDeclaration>node);
|
||||
@ -964,7 +965,8 @@ namespace ts {
|
||||
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
|
||||
}
|
||||
else {
|
||||
bindAnonymousDeclaration(node, SymbolFlags.Class, "__class");
|
||||
let bindingName = node.name ? node.name.text : "__class";
|
||||
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
|
||||
}
|
||||
|
||||
let symbol = node.symbol;
|
||||
|
||||
@ -7303,6 +7303,16 @@ namespace ts {
|
||||
checkGrammarJsxElement(node);
|
||||
checkJsxPreconditions(node);
|
||||
|
||||
// If we're compiling under --jsx react, the symbol 'React' should
|
||||
// be marked as 'used' so we don't incorrectly elide its import. And if there
|
||||
// is no 'React' symbol in scope, we should issue an error.
|
||||
if (compilerOptions.jsx === JsxEmit.React) {
|
||||
let reactSym = resolveName(node.tagName, 'React', SymbolFlags.Value, Diagnostics.Cannot_find_name_0, 'React');
|
||||
if (reactSym) {
|
||||
getSymbolLinks(reactSym).referenced = true;
|
||||
}
|
||||
}
|
||||
|
||||
let targetAttributesType = getJsxElementAttributesType(node);
|
||||
|
||||
let nameTable: Map<boolean> = {};
|
||||
|
||||
@ -2892,33 +2892,36 @@ namespace ts {
|
||||
log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start));
|
||||
}
|
||||
|
||||
// Check if this is a valid completion location
|
||||
if (contextToken && isCompletionListBlocker(contextToken)) {
|
||||
log("Returning an empty list because completion was requested in an invalid position.");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let options = program.getCompilerOptions();
|
||||
let jsx = options.jsx !== JsxEmit.None;
|
||||
let target = options.target;
|
||||
|
||||
// Find the node where completion is requested on, in the case of a completion after
|
||||
// a dot, it is the member access expression other wise, it is a request for all
|
||||
// visible symbols in the scope, and the node is the current location.
|
||||
// Find the node where completion is requested on.
|
||||
// Also determine whether we are trying to complete with members of that node
|
||||
// or attributes of a JSX tag.
|
||||
let node = currentToken;
|
||||
let isRightOfDot = false;
|
||||
let isRightOfOpenTag = false;
|
||||
|
||||
let location = getTouchingPropertyName(sourceFile, position);
|
||||
if(contextToken) {
|
||||
let kind = contextToken.kind;
|
||||
if (kind === SyntaxKind.DotToken && contextToken.parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
node = (<PropertyAccessExpression>contextToken.parent).expression;
|
||||
isRightOfDot = true;
|
||||
if (contextToken) {
|
||||
// Bail out if this is a known invalid completion location
|
||||
if (isCompletionListBlocker(contextToken)) {
|
||||
log("Returning an empty list because completion was requested in an invalid position.");
|
||||
return undefined;
|
||||
}
|
||||
else if (kind === SyntaxKind.DotToken && contextToken.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = (<QualifiedName>contextToken.parent).left;
|
||||
isRightOfDot = true;
|
||||
|
||||
let { parent, kind } = contextToken;
|
||||
if (kind === SyntaxKind.DotToken) {
|
||||
if (parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
node = (<PropertyAccessExpression>contextToken.parent).expression;
|
||||
isRightOfDot = true;
|
||||
}
|
||||
else if (parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = (<QualifiedName>contextToken.parent).left;
|
||||
isRightOfDot = true;
|
||||
}
|
||||
else {
|
||||
// There is nothing that precedes the dot, so this likely just a stray character
|
||||
// or leading into a '...' token. Just bail out instead.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
else if (kind === SyntaxKind.LessThanToken && sourceFile.languageVariant === LanguageVariant.JSX) {
|
||||
isRightOfOpenTag = true;
|
||||
@ -3010,68 +3013,21 @@ namespace ts {
|
||||
}
|
||||
|
||||
function tryGetGlobalSymbols(): boolean {
|
||||
let objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken);
|
||||
let jsxContainer = tryGetContainingJsxElement(contextToken);
|
||||
if (objectLikeContainer) {
|
||||
// We're looking up possible property names from contextual/inferred/declared type.
|
||||
isMemberCompletion = true;
|
||||
let objectLikeContainer: ObjectLiteralExpression | BindingPattern;
|
||||
let importClause: ImportClause;
|
||||
let jsxContainer: JsxOpeningLikeElement;
|
||||
|
||||
let typeForObject: Type;
|
||||
let existingMembers: Declaration[];
|
||||
|
||||
if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
// We are completing on contextual types, but may also include properties
|
||||
// other than those within the declared type.
|
||||
isNewIdentifierLocation = true;
|
||||
|
||||
typeForObject = typeChecker.getContextualType(<ObjectLiteralExpression>objectLikeContainer);
|
||||
existingMembers = (<ObjectLiteralExpression>objectLikeContainer).properties;
|
||||
}
|
||||
else if (objectLikeContainer.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
// We are *only* completing on properties from the type being destructured.
|
||||
isNewIdentifierLocation = false;
|
||||
|
||||
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
|
||||
existingMembers = (<BindingPattern>objectLikeContainer).elements;
|
||||
}
|
||||
else {
|
||||
Debug.fail("Expected object literal or binding pattern, got " + objectLikeContainer.kind);
|
||||
}
|
||||
|
||||
if (!typeForObject) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let typeMembers = typeChecker.getPropertiesOfType(typeForObject);
|
||||
if (typeMembers && typeMembers.length > 0) {
|
||||
// Add filtered items to the completion list
|
||||
symbols = filterObjectMembersList(typeMembers, existingMembers);
|
||||
}
|
||||
return true;
|
||||
if (objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken)) {
|
||||
return tryGetObjectLikeCompletionSymbols(objectLikeContainer);
|
||||
}
|
||||
else if (getAncestor(contextToken, SyntaxKind.ImportClause)) {
|
||||
// cursor is in import clause
|
||||
|
||||
if (importClause = <ImportClause>getAncestor(contextToken, SyntaxKind.ImportClause)) {
|
||||
// cursor is in an import clause
|
||||
// try to show exported member for imported module
|
||||
isMemberCompletion = true;
|
||||
isNewIdentifierLocation = true;
|
||||
if (showCompletionsInImportsClause(contextToken)) {
|
||||
let importDeclaration = <ImportDeclaration>getAncestor(contextToken, SyntaxKind.ImportDeclaration);
|
||||
Debug.assert(importDeclaration !== undefined);
|
||||
|
||||
let exports: Symbol[];
|
||||
if (importDeclaration.moduleSpecifier) {
|
||||
let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier);
|
||||
if (moduleSpecifierSymbol) {
|
||||
exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
//let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration);
|
||||
symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray;
|
||||
}
|
||||
return true;
|
||||
return tryGetImportClauseCompletionSymbols(importClause);
|
||||
}
|
||||
else if (jsxContainer) {
|
||||
|
||||
if (jsxContainer = tryGetContainingJsxElement(contextToken)) {
|
||||
let attrsType: Type;
|
||||
if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) {
|
||||
// Cursor is inside a JSX self-closing element or opening element
|
||||
@ -3144,16 +3100,16 @@ namespace ts {
|
||||
return scope;
|
||||
}
|
||||
|
||||
function isCompletionListBlocker(previousToken: Node): boolean {
|
||||
function isCompletionListBlocker(contextToken: Node): boolean {
|
||||
let start = new Date().getTime();
|
||||
let result = isInStringOrRegularExpressionOrTemplateLiteral(previousToken) ||
|
||||
isIdentifierDefinitionLocation(previousToken) ||
|
||||
isRightOfIllegalDot(previousToken);
|
||||
let result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) ||
|
||||
isIdentifierDefinitionLocation(contextToken) ||
|
||||
isDotOfNumericLiteral(contextToken);
|
||||
log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start));
|
||||
return result;
|
||||
}
|
||||
|
||||
function showCompletionsInImportsClause(node: Node): boolean {
|
||||
function shouldShowCompletionsInImportsClause(node: Node): boolean {
|
||||
if (node) {
|
||||
// import {|
|
||||
// import {a,|
|
||||
@ -3227,12 +3183,12 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isInStringOrRegularExpressionOrTemplateLiteral(previousToken: Node): boolean {
|
||||
if (previousToken.kind === SyntaxKind.StringLiteral
|
||||
|| previousToken.kind === SyntaxKind.RegularExpressionLiteral
|
||||
|| isTemplateLiteralKind(previousToken.kind)) {
|
||||
let start = previousToken.getStart();
|
||||
let end = previousToken.getEnd();
|
||||
function isInStringOrRegularExpressionOrTemplateLiteral(contextToken: Node): boolean {
|
||||
if (contextToken.kind === SyntaxKind.StringLiteral
|
||||
|| contextToken.kind === SyntaxKind.RegularExpressionLiteral
|
||||
|| isTemplateLiteralKind(contextToken.kind)) {
|
||||
let start = contextToken.getStart();
|
||||
let end = contextToken.getEnd();
|
||||
|
||||
// To be "in" one of these literals, the position has to be:
|
||||
// 1. entirely within the token text.
|
||||
@ -3243,14 +3199,94 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (position === end) {
|
||||
return !!(<LiteralExpression>previousToken).isUnterminated ||
|
||||
previousToken.kind === SyntaxKind.RegularExpressionLiteral;
|
||||
return !!(<LiteralExpression>contextToken).isUnterminated
|
||||
|| contextToken.kind === SyntaxKind.RegularExpressionLiteral;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates relevant symbols for completion in object literals and object binding patterns.
|
||||
* Relevant symbols are stored in the captured 'symbols' variable.
|
||||
*
|
||||
* @returns true if 'symbols' was successfully populated; false otherwise.
|
||||
*/
|
||||
function tryGetObjectLikeCompletionSymbols(objectLikeContainer: ObjectLiteralExpression | BindingPattern): boolean {
|
||||
// We're looking up possible property names from contextual/inferred/declared type.
|
||||
isMemberCompletion = true;
|
||||
|
||||
let typeForObject: Type;
|
||||
let existingMembers: Declaration[];
|
||||
|
||||
if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
// We are completing on contextual types, but may also include properties
|
||||
// other than those within the declared type.
|
||||
isNewIdentifierLocation = true;
|
||||
|
||||
typeForObject = typeChecker.getContextualType(<ObjectLiteralExpression>objectLikeContainer);
|
||||
existingMembers = (<ObjectLiteralExpression>objectLikeContainer).properties;
|
||||
}
|
||||
else if (objectLikeContainer.kind === SyntaxKind.ObjectBindingPattern) {
|
||||
// We are *only* completing on properties from the type being destructured.
|
||||
isNewIdentifierLocation = false;
|
||||
|
||||
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
|
||||
existingMembers = (<BindingPattern>objectLikeContainer).elements;
|
||||
}
|
||||
else {
|
||||
Debug.fail("Expected object literal or binding pattern, got " + objectLikeContainer.kind);
|
||||
}
|
||||
|
||||
if (!typeForObject) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let typeMembers = typeChecker.getPropertiesOfType(typeForObject);
|
||||
if (typeMembers && typeMembers.length > 0) {
|
||||
// Add filtered items to the completion list
|
||||
symbols = filterObjectMembersList(typeMembers, existingMembers);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates relevant symbols for completion in import clauses; for instance,
|
||||
*
|
||||
* import { $ } from "moduleName";
|
||||
*
|
||||
* Relevant symbols are stored in the captured 'symbols' variable.
|
||||
*
|
||||
* @returns true if 'symbols' was successfully populated; false otherwise.
|
||||
*/
|
||||
function tryGetImportClauseCompletionSymbols(importClause: ImportClause): boolean {
|
||||
// cursor is in import clause
|
||||
// try to show exported member for imported module
|
||||
if (shouldShowCompletionsInImportsClause(contextToken)) {
|
||||
isMemberCompletion = true;
|
||||
isNewIdentifierLocation = false;
|
||||
|
||||
let importDeclaration = <ImportDeclaration>importClause.parent;
|
||||
Debug.assert(importDeclaration !== undefined && importDeclaration.kind === SyntaxKind.ImportDeclaration);
|
||||
|
||||
let exports: Symbol[];
|
||||
let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier);
|
||||
if (moduleSpecifierSymbol) {
|
||||
exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol);
|
||||
}
|
||||
|
||||
//let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration);
|
||||
symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray;
|
||||
}
|
||||
else {
|
||||
isMemberCompletion = false;
|
||||
isNewIdentifierLocation = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the immediate owning object literal or binding pattern of a context token,
|
||||
* on the condition that one exists and that the context implies completion should be given.
|
||||
@ -3318,101 +3354,98 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isIdentifierDefinitionLocation(previousToken: Node): boolean {
|
||||
if (previousToken) {
|
||||
let containingNodeKind = previousToken.parent.kind;
|
||||
switch (previousToken.kind) {
|
||||
case SyntaxKind.CommaToken:
|
||||
return containingNodeKind === SyntaxKind.VariableDeclaration ||
|
||||
containingNodeKind === SyntaxKind.VariableDeclarationList ||
|
||||
containingNodeKind === SyntaxKind.VariableStatement ||
|
||||
containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, |
|
||||
isFunction(containingNodeKind) ||
|
||||
containingNodeKind === SyntaxKind.ClassDeclaration || // class A<T, |
|
||||
containingNodeKind === SyntaxKind.FunctionDeclaration || // function A<T, |
|
||||
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A<T, |
|
||||
containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [x, y|
|
||||
function isIdentifierDefinitionLocation(contextToken: Node): boolean {
|
||||
let containingNodeKind = contextToken.parent.kind;
|
||||
switch (contextToken.kind) {
|
||||
case SyntaxKind.CommaToken:
|
||||
return containingNodeKind === SyntaxKind.VariableDeclaration ||
|
||||
containingNodeKind === SyntaxKind.VariableDeclarationList ||
|
||||
containingNodeKind === SyntaxKind.VariableStatement ||
|
||||
containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, |
|
||||
isFunction(containingNodeKind) ||
|
||||
containingNodeKind === SyntaxKind.ClassDeclaration || // class A<T, |
|
||||
containingNodeKind === SyntaxKind.FunctionDeclaration || // function A<T, |
|
||||
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A<T, |
|
||||
containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [x, y|
|
||||
|
||||
case SyntaxKind.DotToken:
|
||||
return containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [.|
|
||||
case SyntaxKind.DotToken:
|
||||
return containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [.|
|
||||
|
||||
case SyntaxKind.ColonToken:
|
||||
return containingNodeKind === SyntaxKind.BindingElement; // var {x :html|
|
||||
case SyntaxKind.ColonToken:
|
||||
return containingNodeKind === SyntaxKind.BindingElement; // var {x :html|
|
||||
|
||||
case SyntaxKind.OpenBracketToken:
|
||||
return containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [x|
|
||||
case SyntaxKind.OpenBracketToken:
|
||||
return containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [x|
|
||||
|
||||
case SyntaxKind.OpenParenToken:
|
||||
return containingNodeKind === SyntaxKind.CatchClause ||
|
||||
isFunction(containingNodeKind);
|
||||
case SyntaxKind.OpenParenToken:
|
||||
return containingNodeKind === SyntaxKind.CatchClause ||
|
||||
isFunction(containingNodeKind);
|
||||
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { |
|
||||
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface a { |
|
||||
containingNodeKind === SyntaxKind.TypeLiteral; // let x : { |
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { |
|
||||
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface a { |
|
||||
containingNodeKind === SyntaxKind.TypeLiteral; // let x : { |
|
||||
|
||||
case SyntaxKind.SemicolonToken:
|
||||
return containingNodeKind === SyntaxKind.PropertySignature &&
|
||||
previousToken.parent && previousToken.parent.parent &&
|
||||
(previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; |
|
||||
previousToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; |
|
||||
case SyntaxKind.SemicolonToken:
|
||||
return containingNodeKind === SyntaxKind.PropertySignature &&
|
||||
contextToken.parent && contextToken.parent.parent &&
|
||||
(contextToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; |
|
||||
contextToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; |
|
||||
|
||||
case SyntaxKind.LessThanToken:
|
||||
return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< |
|
||||
containingNodeKind === SyntaxKind.FunctionDeclaration || // function A< |
|
||||
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A< |
|
||||
isFunction(containingNodeKind);
|
||||
case SyntaxKind.LessThanToken:
|
||||
return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< |
|
||||
containingNodeKind === SyntaxKind.FunctionDeclaration || // function A< |
|
||||
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A< |
|
||||
isFunction(containingNodeKind);
|
||||
|
||||
case SyntaxKind.StaticKeyword:
|
||||
return containingNodeKind === SyntaxKind.PropertyDeclaration;
|
||||
case SyntaxKind.StaticKeyword:
|
||||
return containingNodeKind === SyntaxKind.PropertyDeclaration;
|
||||
|
||||
case SyntaxKind.DotDotDotToken:
|
||||
return containingNodeKind === SyntaxKind.Parameter ||
|
||||
containingNodeKind === SyntaxKind.Constructor ||
|
||||
(previousToken.parent && previousToken.parent.parent &&
|
||||
previousToken.parent.parent.kind === SyntaxKind.ArrayBindingPattern); // var [...z|
|
||||
case SyntaxKind.DotDotDotToken:
|
||||
return containingNodeKind === SyntaxKind.Parameter ||
|
||||
(contextToken.parent && contextToken.parent.parent &&
|
||||
contextToken.parent.parent.kind === SyntaxKind.ArrayBindingPattern); // var [...z|
|
||||
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
return containingNodeKind === SyntaxKind.Parameter;
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
return containingNodeKind === SyntaxKind.Parameter;
|
||||
|
||||
case SyntaxKind.ClassKeyword:
|
||||
case SyntaxKind.EnumKeyword:
|
||||
case SyntaxKind.InterfaceKeyword:
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
case SyntaxKind.VarKeyword:
|
||||
case SyntaxKind.GetKeyword:
|
||||
case SyntaxKind.SetKeyword:
|
||||
case SyntaxKind.ImportKeyword:
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.YieldKeyword:
|
||||
case SyntaxKind.TypeKeyword: // type htm|
|
||||
return true;
|
||||
}
|
||||
case SyntaxKind.ClassKeyword:
|
||||
case SyntaxKind.EnumKeyword:
|
||||
case SyntaxKind.InterfaceKeyword:
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
case SyntaxKind.VarKeyword:
|
||||
case SyntaxKind.GetKeyword:
|
||||
case SyntaxKind.SetKeyword:
|
||||
case SyntaxKind.ImportKeyword:
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.YieldKeyword:
|
||||
case SyntaxKind.TypeKeyword: // type htm|
|
||||
return true;
|
||||
}
|
||||
|
||||
// Previous token may have been a keyword that was converted to an identifier.
|
||||
switch (previousToken.getText()) {
|
||||
case "class":
|
||||
case "interface":
|
||||
case "enum":
|
||||
case "function":
|
||||
case "var":
|
||||
case "static":
|
||||
case "let":
|
||||
case "const":
|
||||
case "yield":
|
||||
return true;
|
||||
}
|
||||
// Previous token may have been a keyword that was converted to an identifier.
|
||||
switch (contextToken.getText()) {
|
||||
case "class":
|
||||
case "interface":
|
||||
case "enum":
|
||||
case "function":
|
||||
case "var":
|
||||
case "static":
|
||||
case "let":
|
||||
case "const":
|
||||
case "yield":
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isRightOfIllegalDot(previousToken: Node): boolean {
|
||||
if (previousToken && previousToken.kind === SyntaxKind.NumericLiteral) {
|
||||
let text = previousToken.getFullText();
|
||||
function isDotOfNumericLiteral(contextToken: Node): boolean {
|
||||
if (contextToken.kind === SyntaxKind.NumericLiteral) {
|
||||
let text = contextToken.getFullText();
|
||||
return text.charAt(text.length - 1) === ".";
|
||||
}
|
||||
|
||||
|
||||
@ -28,13 +28,13 @@ function M() {
|
||||
}
|
||||
|
||||
var v = new m<number>();
|
||||
>v : <number>
|
||||
>new m<number>() : <number>
|
||||
>v : C<number>
|
||||
>new m<number>() : C<number>
|
||||
>m : typeof C
|
||||
|
||||
return v.f<string>();
|
||||
>v.f<string>() : { t: string; x: number; }
|
||||
>v.f : <T>() => { t: T; x: number; }
|
||||
>v : <number>
|
||||
>v : C<number>
|
||||
>f : <T>() => { t: T; x: number; }
|
||||
}
|
||||
|
||||
36
tests/baselines/reference/tsxElementResolution19.js
Normal file
36
tests/baselines/reference/tsxElementResolution19.js
Normal file
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/conformance/jsx/tsxElementResolution19.tsx] ////
|
||||
|
||||
//// [react.d.ts]
|
||||
|
||||
declare module "react" {
|
||||
|
||||
}
|
||||
|
||||
//// [file1.tsx]
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
}
|
||||
export class MyClass { }
|
||||
|
||||
//// [file2.tsx]
|
||||
|
||||
// Should not elide React import
|
||||
import * as React from 'react';
|
||||
import {MyClass} from './file1';
|
||||
|
||||
<MyClass />;
|
||||
|
||||
|
||||
//// [file1.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
var MyClass = (function () {
|
||||
function MyClass() {
|
||||
}
|
||||
return MyClass;
|
||||
})();
|
||||
exports.MyClass = MyClass;
|
||||
});
|
||||
//// [file2.js]
|
||||
define(["require", "exports", 'react', './file1'], function (require, exports, React, file1_1) {
|
||||
React.createElement(file1_1.MyClass, null);
|
||||
});
|
||||
28
tests/baselines/reference/tsxElementResolution19.symbols
Normal file
28
tests/baselines/reference/tsxElementResolution19.symbols
Normal file
@ -0,0 +1,28 @@
|
||||
=== tests/cases/conformance/jsx/react.d.ts ===
|
||||
|
||||
No type information for this code.declare module "react" {
|
||||
No type information for this code.
|
||||
No type information for this code.}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/conformance/jsx/file1.tsx ===
|
||||
declare module JSX {
|
||||
>JSX : Symbol(JSX, Decl(file1.tsx, 0, 0))
|
||||
|
||||
interface Element { }
|
||||
>Element : Symbol(Element, Decl(file1.tsx, 0, 20))
|
||||
}
|
||||
export class MyClass { }
|
||||
>MyClass : Symbol(MyClass, Decl(file1.tsx, 2, 1))
|
||||
|
||||
=== tests/cases/conformance/jsx/file2.tsx ===
|
||||
|
||||
// Should not elide React import
|
||||
import * as React from 'react';
|
||||
>React : Symbol(React, Decl(file2.tsx, 2, 6))
|
||||
|
||||
import {MyClass} from './file1';
|
||||
>MyClass : Symbol(MyClass, Decl(file2.tsx, 3, 8))
|
||||
|
||||
<MyClass />;
|
||||
>MyClass : Symbol(MyClass, Decl(file2.tsx, 3, 8))
|
||||
|
||||
29
tests/baselines/reference/tsxElementResolution19.types
Normal file
29
tests/baselines/reference/tsxElementResolution19.types
Normal file
@ -0,0 +1,29 @@
|
||||
=== tests/cases/conformance/jsx/react.d.ts ===
|
||||
|
||||
No type information for this code.declare module "react" {
|
||||
No type information for this code.
|
||||
No type information for this code.}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/conformance/jsx/file1.tsx ===
|
||||
declare module JSX {
|
||||
>JSX : any
|
||||
|
||||
interface Element { }
|
||||
>Element : Element
|
||||
}
|
||||
export class MyClass { }
|
||||
>MyClass : MyClass
|
||||
|
||||
=== tests/cases/conformance/jsx/file2.tsx ===
|
||||
|
||||
// Should not elide React import
|
||||
import * as React from 'react';
|
||||
>React : typeof React
|
||||
|
||||
import {MyClass} from './file1';
|
||||
>MyClass : typeof MyClass
|
||||
|
||||
<MyClass />;
|
||||
><MyClass /> : any
|
||||
>MyClass : typeof MyClass
|
||||
|
||||
@ -5,6 +5,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p;
|
||||
var selfClosed1 = <div />;
|
||||
|
||||
@ -12,133 +12,135 @@ declare module JSX {
|
||||
>s : Symbol(s, Decl(tsxReactEmit1.tsx, 3, 3))
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
>React : Symbol(React, Decl(tsxReactEmit1.tsx, 6, 11))
|
||||
|
||||
var p;
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
|
||||
var selfClosed1 = <div />;
|
||||
>selfClosed1 : Symbol(selfClosed1, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>selfClosed1 : Symbol(selfClosed1, Decl(tsxReactEmit1.tsx, 9, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
|
||||
var selfClosed2 = <div x="1" />;
|
||||
>selfClosed2 : Symbol(selfClosed2, Decl(tsxReactEmit1.tsx, 9, 3))
|
||||
>selfClosed2 : Symbol(selfClosed2, Decl(tsxReactEmit1.tsx, 10, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
|
||||
var selfClosed3 = <div x='1' />;
|
||||
>selfClosed3 : Symbol(selfClosed3, Decl(tsxReactEmit1.tsx, 10, 3))
|
||||
>selfClosed3 : Symbol(selfClosed3, Decl(tsxReactEmit1.tsx, 11, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
|
||||
var selfClosed4 = <div x="1" y='0' />;
|
||||
>selfClosed4 : Symbol(selfClosed4, Decl(tsxReactEmit1.tsx, 11, 3))
|
||||
>selfClosed4 : Symbol(selfClosed4, Decl(tsxReactEmit1.tsx, 12, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
>y : Symbol(unknown)
|
||||
|
||||
var selfClosed5 = <div x={0} y='0' />;
|
||||
>selfClosed5 : Symbol(selfClosed5, Decl(tsxReactEmit1.tsx, 12, 3))
|
||||
>selfClosed5 : Symbol(selfClosed5, Decl(tsxReactEmit1.tsx, 13, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
>y : Symbol(unknown)
|
||||
|
||||
var selfClosed6 = <div x={"1"} y='0' />;
|
||||
>selfClosed6 : Symbol(selfClosed6, Decl(tsxReactEmit1.tsx, 13, 3))
|
||||
>selfClosed6 : Symbol(selfClosed6, Decl(tsxReactEmit1.tsx, 14, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
>y : Symbol(unknown)
|
||||
|
||||
var selfClosed7 = <div x={p} y='p' b />;
|
||||
>selfClosed7 : Symbol(selfClosed7, Decl(tsxReactEmit1.tsx, 14, 3))
|
||||
>selfClosed7 : Symbol(selfClosed7, Decl(tsxReactEmit1.tsx, 15, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
>y : Symbol(unknown)
|
||||
>b : Symbol(unknown)
|
||||
|
||||
var openClosed1 = <div></div>;
|
||||
>openClosed1 : Symbol(openClosed1, Decl(tsxReactEmit1.tsx, 16, 3))
|
||||
>openClosed1 : Symbol(openClosed1, Decl(tsxReactEmit1.tsx, 17, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
|
||||
var openClosed2 = <div n='m'>foo</div>;
|
||||
>openClosed2 : Symbol(openClosed2, Decl(tsxReactEmit1.tsx, 17, 3))
|
||||
>openClosed2 : Symbol(openClosed2, Decl(tsxReactEmit1.tsx, 18, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>n : Symbol(unknown)
|
||||
|
||||
var openClosed3 = <div n='m'>{p}</div>;
|
||||
>openClosed3 : Symbol(openClosed3, Decl(tsxReactEmit1.tsx, 18, 3))
|
||||
>openClosed3 : Symbol(openClosed3, Decl(tsxReactEmit1.tsx, 19, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>n : Symbol(unknown)
|
||||
|
||||
var openClosed4 = <div n='m'>{p < p}</div>;
|
||||
>openClosed4 : Symbol(openClosed4, Decl(tsxReactEmit1.tsx, 19, 3))
|
||||
>openClosed4 : Symbol(openClosed4, Decl(tsxReactEmit1.tsx, 20, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>n : Symbol(unknown)
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
|
||||
var openClosed5 = <div n='m' b>{p > p}</div>;
|
||||
>openClosed5 : Symbol(openClosed5, Decl(tsxReactEmit1.tsx, 20, 3))
|
||||
>openClosed5 : Symbol(openClosed5, Decl(tsxReactEmit1.tsx, 21, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>n : Symbol(unknown)
|
||||
>b : Symbol(unknown)
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
|
||||
class SomeClass {
|
||||
>SomeClass : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 20, 45))
|
||||
>SomeClass : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45))
|
||||
|
||||
f() {
|
||||
>f : Symbol(f, Decl(tsxReactEmit1.tsx, 22, 17))
|
||||
>f : Symbol(f, Decl(tsxReactEmit1.tsx, 23, 17))
|
||||
|
||||
var rewrites1 = <div>{() => this}</div>;
|
||||
>rewrites1 : Symbol(rewrites1, Decl(tsxReactEmit1.tsx, 24, 5))
|
||||
>rewrites1 : Symbol(rewrites1, Decl(tsxReactEmit1.tsx, 25, 5))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 20, 45))
|
||||
>this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45))
|
||||
|
||||
var rewrites2 = <div>{[p, ...p, p]}</div>;
|
||||
>rewrites2 : Symbol(rewrites2, Decl(tsxReactEmit1.tsx, 25, 5))
|
||||
>rewrites2 : Symbol(rewrites2, Decl(tsxReactEmit1.tsx, 26, 5))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
|
||||
var rewrites3 = <div>{{p}}</div>;
|
||||
>rewrites3 : Symbol(rewrites3, Decl(tsxReactEmit1.tsx, 26, 5))
|
||||
>rewrites3 : Symbol(rewrites3, Decl(tsxReactEmit1.tsx, 27, 5))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 26, 25))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 27, 25))
|
||||
|
||||
var rewrites4 = <div a={() => this}></div>;
|
||||
>rewrites4 : Symbol(rewrites4, Decl(tsxReactEmit1.tsx, 28, 5))
|
||||
>rewrites4 : Symbol(rewrites4, Decl(tsxReactEmit1.tsx, 29, 5))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>a : Symbol(unknown)
|
||||
>this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 20, 45))
|
||||
>this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45))
|
||||
|
||||
var rewrites5 = <div a={[p, ...p, p]}></div>;
|
||||
>rewrites5 : Symbol(rewrites5, Decl(tsxReactEmit1.tsx, 29, 5))
|
||||
>rewrites5 : Symbol(rewrites5, Decl(tsxReactEmit1.tsx, 30, 5))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>a : Symbol(unknown)
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3))
|
||||
|
||||
var rewrites6 = <div a={{p}}></div>;
|
||||
>rewrites6 : Symbol(rewrites6, Decl(tsxReactEmit1.tsx, 30, 5))
|
||||
>rewrites6 : Symbol(rewrites6, Decl(tsxReactEmit1.tsx, 31, 5))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
>a : Symbol(unknown)
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 30, 27))
|
||||
>p : Symbol(p, Decl(tsxReactEmit1.tsx, 31, 27))
|
||||
}
|
||||
}
|
||||
|
||||
var whitespace1 = <div> </div>;
|
||||
>whitespace1 : Symbol(whitespace1, Decl(tsxReactEmit1.tsx, 34, 3))
|
||||
>whitespace1 : Symbol(whitespace1, Decl(tsxReactEmit1.tsx, 35, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
|
||||
var whitespace2 = <div> {p} </div>;
|
||||
>whitespace2 : Symbol(whitespace2, Decl(tsxReactEmit1.tsx, 35, 3))
|
||||
>whitespace2 : Symbol(whitespace2, Decl(tsxReactEmit1.tsx, 36, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
|
||||
var whitespace3 = <div>
|
||||
>whitespace3 : Symbol(whitespace3, Decl(tsxReactEmit1.tsx, 36, 3))
|
||||
>whitespace3 : Symbol(whitespace3, Decl(tsxReactEmit1.tsx, 37, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22))
|
||||
|
||||
{p}
|
||||
|
||||
@ -12,6 +12,8 @@ declare module JSX {
|
||||
>s : string
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
>React : any
|
||||
|
||||
var p;
|
||||
>p : any
|
||||
|
||||
@ -5,6 +5,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p1, p2, p3;
|
||||
var spreads1 = <div {...p1}>{p2}</div>;
|
||||
|
||||
@ -12,32 +12,34 @@ declare module JSX {
|
||||
>s : Symbol(s, Decl(tsxReactEmit2.tsx, 3, 3))
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
>React : Symbol(React, Decl(tsxReactEmit2.tsx, 6, 11))
|
||||
|
||||
var p1, p2, p3;
|
||||
>p1 : Symbol(p1, Decl(tsxReactEmit2.tsx, 7, 3))
|
||||
>p2 : Symbol(p2, Decl(tsxReactEmit2.tsx, 7, 7))
|
||||
>p3 : Symbol(p3, Decl(tsxReactEmit2.tsx, 7, 11))
|
||||
>p1 : Symbol(p1, Decl(tsxReactEmit2.tsx, 8, 3))
|
||||
>p2 : Symbol(p2, Decl(tsxReactEmit2.tsx, 8, 7))
|
||||
>p3 : Symbol(p3, Decl(tsxReactEmit2.tsx, 8, 11))
|
||||
|
||||
var spreads1 = <div {...p1}>{p2}</div>;
|
||||
>spreads1 : Symbol(spreads1, Decl(tsxReactEmit2.tsx, 8, 3))
|
||||
>spreads1 : Symbol(spreads1, Decl(tsxReactEmit2.tsx, 9, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22))
|
||||
|
||||
var spreads2 = <div {...p1}>{p2}</div>;
|
||||
>spreads2 : Symbol(spreads2, Decl(tsxReactEmit2.tsx, 9, 3))
|
||||
>spreads2 : Symbol(spreads2, Decl(tsxReactEmit2.tsx, 10, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22))
|
||||
|
||||
var spreads3 = <div x={p3} {...p1}>{p2}</div>;
|
||||
>spreads3 : Symbol(spreads3, Decl(tsxReactEmit2.tsx, 10, 3))
|
||||
>spreads3 : Symbol(spreads3, Decl(tsxReactEmit2.tsx, 11, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
|
||||
var spreads4 = <div {...p1} x={p3} >{p2}</div>;
|
||||
>spreads4 : Symbol(spreads4, Decl(tsxReactEmit2.tsx, 11, 3))
|
||||
>spreads4 : Symbol(spreads4, Decl(tsxReactEmit2.tsx, 12, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
|
||||
var spreads5 = <div x={p2} {...p1} y={p3}>{p2}</div>;
|
||||
>spreads5 : Symbol(spreads5, Decl(tsxReactEmit2.tsx, 12, 3))
|
||||
>spreads5 : Symbol(spreads5, Decl(tsxReactEmit2.tsx, 13, 3))
|
||||
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22))
|
||||
>x : Symbol(unknown)
|
||||
>y : Symbol(unknown)
|
||||
|
||||
@ -12,6 +12,8 @@ declare module JSX {
|
||||
>s : string
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
>React : any
|
||||
|
||||
var p1, p2, p3;
|
||||
>p1 : any
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
//// [tsxReactEmit3.tsx]
|
||||
|
||||
declare module JSX { interface Element { } }
|
||||
declare var React: any;
|
||||
|
||||
declare var Foo, Bar, baz;
|
||||
|
||||
|
||||
@ -4,15 +4,18 @@ declare module JSX { interface Element { } }
|
||||
>JSX : Symbol(JSX, Decl(tsxReactEmit3.tsx, 0, 0))
|
||||
>Element : Symbol(Element, Decl(tsxReactEmit3.tsx, 1, 20))
|
||||
|
||||
declare var React: any;
|
||||
>React : Symbol(React, Decl(tsxReactEmit3.tsx, 2, 11))
|
||||
|
||||
declare var Foo, Bar, baz;
|
||||
>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 3, 11))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16))
|
||||
>baz : Symbol(baz, Decl(tsxReactEmit3.tsx, 3, 21))
|
||||
>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 4, 11))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16))
|
||||
>baz : Symbol(baz, Decl(tsxReactEmit3.tsx, 4, 21))
|
||||
|
||||
<Foo> <Bar> q </Bar> <Bar/> s <Bar/><Bar/></Foo>;
|
||||
>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 3, 11))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16))
|
||||
>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 4, 11))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16))
|
||||
>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16))
|
||||
|
||||
|
||||
@ -4,6 +4,9 @@ declare module JSX { interface Element { } }
|
||||
>JSX : any
|
||||
>Element : Element
|
||||
|
||||
declare var React: any;
|
||||
>React : any
|
||||
|
||||
declare var Foo, Bar, baz;
|
||||
>Foo : any
|
||||
>Bar : any
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/jsx/tsxReactEmit4.tsx(11,5): error TS2304: Cannot find name 'blah'.
|
||||
tests/cases/conformance/jsx/tsxReactEmit4.tsx(12,5): error TS2304: Cannot find name 'blah'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/tsxReactEmit4.tsx (1 errors) ====
|
||||
@ -8,6 +8,7 @@ tests/cases/conformance/jsx/tsxReactEmit4.tsx(11,5): error TS2304: Cannot find n
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p;
|
||||
var openClosed1 = <div>
|
||||
|
||||
@ -5,6 +5,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p;
|
||||
var openClosed1 = <div>
|
||||
|
||||
@ -5,6 +5,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
// THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING
|
||||
// WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT
|
||||
|
||||
@ -12,12 +12,14 @@ declare module JSX {
|
||||
>s : Symbol(s, Decl(tsxReactEmitWhitespace.tsx, 3, 3))
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
>React : Symbol(React, Decl(tsxReactEmitWhitespace.tsx, 6, 11))
|
||||
|
||||
// THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING
|
||||
// WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT
|
||||
|
||||
var p = 0;
|
||||
>p : Symbol(p, Decl(tsxReactEmitWhitespace.tsx, 10, 3))
|
||||
>p : Symbol(p, Decl(tsxReactEmitWhitespace.tsx, 11, 3))
|
||||
|
||||
// Emit " "
|
||||
<div> </div>;
|
||||
|
||||
@ -12,6 +12,8 @@ declare module JSX {
|
||||
>s : string
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
>React : any
|
||||
|
||||
// THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING
|
||||
// WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
// OK
|
||||
<test1 x={0}/>; // OK
|
||||
<test1 />; // OK
|
||||
<test1 data-x={true}/>; // OK
|
||||
<test2 reqd='true'/>; // OK
|
||||
<test2 reqd={'true'}/>; // OK
|
||||
// Errors
|
||||
<test1 x={'0'}/>; // Error, '0' is not number
|
||||
<test1 y={0}/>; // Error, no property "y"
|
||||
<test1 y="foo"/>; // Error, no property "y"
|
||||
<test1 x="32"/>; // Error, "32" is not number
|
||||
// TODO attribute 'var' should be parseable
|
||||
// <test1 var="10" />; // Error, no 'var' property
|
||||
<test2 />; // Error, missing reqd
|
||||
<test2 reqd={10}/>; // Error, reqd is not string
|
||||
@ -1,5 +0,0 @@
|
||||
// OK
|
||||
<test1 c1={function (x) { return x.length; }}/>; // OK
|
||||
<test1 data-c1={function (x) { return x.leng; }}/>; // OK
|
||||
// Errors
|
||||
<test1 c1={function (x) { return x.leng; }}/>; // Error, no leng on 'string'
|
||||
@ -1,21 +0,0 @@
|
||||
// OK
|
||||
var obj1 = { x: 'foo' };
|
||||
<test1 {...obj1}/>;
|
||||
// Error, x is not string
|
||||
var obj2 = { x: 32 };
|
||||
<test1 {...obj2}/>;
|
||||
// Error, x is missing
|
||||
var obj3 = { y: 32 };
|
||||
<test1 {...obj3}/>;
|
||||
// OK
|
||||
var obj4 = { x: 32, y: 32 };
|
||||
<test1 {...obj4} x="ok"/>;
|
||||
// Error
|
||||
var obj5 = { x: 32, y: 32 };
|
||||
<test1 x="ok" {...obj5}/>;
|
||||
// OK
|
||||
var obj6 = { x: 'ok', y: 32, extra: 100 };
|
||||
<test1 {...obj6}/>;
|
||||
// Error
|
||||
var obj7 = { x: 'foo' };
|
||||
<test1 x={32} {...obj7}/>;
|
||||
@ -1,4 +0,0 @@
|
||||
// OK
|
||||
<test1 {...{ x: function (n) { return 0; } }}/>;
|
||||
// Error, no member 'len' on 'string'
|
||||
<test1 {...{ x: function (n) { return n.len; } }}/>;
|
||||
@ -1,11 +0,0 @@
|
||||
function make1(obj) {
|
||||
return <test1 {...obj}/>; // OK
|
||||
}
|
||||
function make2(obj) {
|
||||
return <test1 {...obj}/>; // Error (x is number, not string)
|
||||
}
|
||||
function make3(obj) {
|
||||
return <test1 {...obj}/>; // Error, missing x
|
||||
}
|
||||
<test1 {...{}}/>; // Error, missing x
|
||||
<test2 {...{}}/>; // OK
|
||||
@ -1,4 +0,0 @@
|
||||
// OK
|
||||
<div />;
|
||||
// Fail
|
||||
<span />;
|
||||
@ -1,6 +0,0 @@
|
||||
var Obj1;
|
||||
<Obj1 x={10}/>; // OK
|
||||
var Obj2;
|
||||
<Obj2 x={10}/>; // Error
|
||||
var Obj3;
|
||||
<Obj3 x={10}/>; // OK
|
||||
@ -1,9 +0,0 @@
|
||||
var obj1;
|
||||
<obj1 x={10}/>; // OK
|
||||
var obj2;
|
||||
<obj2 x={10}/>; // OK
|
||||
var obj3;
|
||||
<obj3 x={10}/>; // Error
|
||||
var obj4;
|
||||
<obj4 x={10}/>; // OK
|
||||
<obj4 x={'10'}/>; // Error
|
||||
@ -1,2 +0,0 @@
|
||||
var obj1;
|
||||
<obj1 x={10}/>; // Error
|
||||
@ -1,2 +0,0 @@
|
||||
var obj1;
|
||||
<obj1 x={10}/>; // OK
|
||||
@ -1,2 +0,0 @@
|
||||
var obj1;
|
||||
<obj1 x={10}/>; // Error
|
||||
@ -1,2 +0,0 @@
|
||||
var obj1;
|
||||
<obj1 x={10}/>; // Error (JSX.Element is missing)
|
||||
21
tests/cases/conformance/jsx/tsxElementResolution19.tsx
Normal file
21
tests/cases/conformance/jsx/tsxElementResolution19.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
//@jsx: react
|
||||
//@module: amd
|
||||
|
||||
//@filename: react.d.ts
|
||||
declare module "react" {
|
||||
|
||||
}
|
||||
|
||||
//@filename: file1.tsx
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
}
|
||||
export class MyClass { }
|
||||
|
||||
//@filename: file2.tsx
|
||||
|
||||
// Should not elide React import
|
||||
import * as React from 'react';
|
||||
import {MyClass} from './file1';
|
||||
|
||||
<MyClass />;
|
||||
@ -1,14 +0,0 @@
|
||||
var my;
|
||||
(function (my) {
|
||||
})(my || (my = {}));
|
||||
// OK
|
||||
<my.div n='x'/>;
|
||||
// Error
|
||||
<my.other />;
|
||||
var q;
|
||||
(function (q) {
|
||||
// OK
|
||||
<mine.div n='x'/>;
|
||||
// Error
|
||||
<mine.non />;
|
||||
})(q || (q = {}));
|
||||
@ -1,15 +0,0 @@
|
||||
// Error
|
||||
var div = 3;
|
||||
<div />;
|
||||
// OK
|
||||
function fact() { return null; }
|
||||
<fact />;
|
||||
// Error
|
||||
function fnum() { return 42; }
|
||||
<fnum />;
|
||||
var obj1;
|
||||
<obj1 />; // OK, prefer construct signatures
|
||||
var obj2;
|
||||
<obj2 />; // Error
|
||||
var obj3;
|
||||
<obj3 />; // Error
|
||||
@ -1,6 +0,0 @@
|
||||
var obj1;
|
||||
<obj1 />; // Error, return type is not an object type
|
||||
var obj2;
|
||||
<obj2 />; // Error, return type is not an object type
|
||||
var obj3;
|
||||
<obj3 x={42}/>; // OK
|
||||
@ -1,34 +0,0 @@
|
||||
var p;
|
||||
/*
|
||||
var selfClosed1 = <div />;
|
||||
var selfClosed2 = <div x="1" />;
|
||||
var selfClosed3 = <div x='1' />;
|
||||
var selfClosed4 = <div x="1" y='0' />;
|
||||
var selfClosed5 = <div x={0} y='0' />;
|
||||
var selfClosed6 = <div x={"1"} y='0' />;
|
||||
var selfClosed7 = <div x={p} y='p' />;
|
||||
|
||||
var openClosed1 = <div></div>;
|
||||
var openClosed2 = <div n='m'>foo</div>;
|
||||
var openClosed3 = <div n='m'>{p}</div>;
|
||||
var openClosed4 = <div n='m'>{p < p}</div>;
|
||||
var openClosed5 = <div n='m'>{p > p}</div>;
|
||||
*/
|
||||
var SomeClass = (function () {
|
||||
function SomeClass() {
|
||||
}
|
||||
SomeClass.prototype.f = function () {
|
||||
var _this = this;
|
||||
var rewrites1 = <div>{function () { return _this; }}</div>;
|
||||
var rewrites4 = <div a={function () { return _this; }}></div>;
|
||||
};
|
||||
return SomeClass;
|
||||
})();
|
||||
/*
|
||||
var q = () => this;
|
||||
var rewrites2 = <div>{[p, ...p, p]}</div>;
|
||||
var rewrites3 = <div>{{p}}</div>;
|
||||
|
||||
var rewrites5 = <div a={[p, ...p, p]}></div>;
|
||||
var rewrites6 = <div a={{p}}></div>;
|
||||
*/
|
||||
@ -1,41 +0,0 @@
|
||||
var M;
|
||||
(function (M) {
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
return Foo;
|
||||
})();
|
||||
M.Foo = Foo;
|
||||
var S;
|
||||
(function (S) {
|
||||
var Bar = (function () {
|
||||
function Bar() {
|
||||
}
|
||||
return Bar;
|
||||
})();
|
||||
S.Bar = Bar;
|
||||
})(S = M.S || (M.S = {}));
|
||||
})(M || (M = {}));
|
||||
var M;
|
||||
(function (M) {
|
||||
// Emit M.Foo
|
||||
M.Foo, <M.Foo />;
|
||||
var S;
|
||||
(function (S) {
|
||||
// Emit M.Foo
|
||||
M.Foo, <M.Foo />;
|
||||
// Emit S.Bar
|
||||
S.Bar, <S.Bar />;
|
||||
})(S = M.S || (M.S = {}));
|
||||
})(M || (M = {}));
|
||||
var M;
|
||||
(function (M) {
|
||||
// Emit M.S.Bar
|
||||
M.S.Bar, <M.S.Bar />;
|
||||
})(M || (M = {}));
|
||||
var M;
|
||||
(function (M_1) {
|
||||
var M = 100;
|
||||
// Emit M_1.Foo
|
||||
M_1.Foo, <M_1.Foo />;
|
||||
})(M || (M = {}));
|
||||
@ -6,6 +6,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p;
|
||||
var selfClosed1 = <div />;
|
||||
|
||||
@ -6,6 +6,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p1, p2, p3;
|
||||
var spreads1 = <div {...p1}>{p2}</div>;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
//@filename: test.tsx
|
||||
|
||||
declare module JSX { interface Element { } }
|
||||
declare var React: any;
|
||||
|
||||
declare var Foo, Bar, baz;
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
var p;
|
||||
var openClosed1 = <div>
|
||||
|
||||
@ -6,6 +6,7 @@ declare module JSX {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
// THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING
|
||||
// WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @Filename: m1.ts
|
||||
////export var foo: number = 1;
|
||||
////export function bar() { return 10; }
|
||||
////export function baz() { return 10; }
|
||||
|
||||
// @Filename: m2.ts
|
||||
////import {/*1*/, /*2*/ from "m1"
|
||||
////import {/*3*/} from "m1"
|
||||
////import {foo,/*4*/ from "m1"
|
||||
////import {bar as /*5*/, /*6*/ from "m1"
|
||||
////import {foo, bar, baz as b,/*7*/} from "m1"
|
||||
function verifyCompletionAtMarker(marker: string, ...completions: string[]) {
|
||||
goTo.marker(marker);
|
||||
if (completions.length) {
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
verify.completionListContains(completions[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
verify.completionListIsEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
verifyCompletionAtMarker("1", "foo", "bar", "baz");
|
||||
verifyCompletionAtMarker("2", "foo", "bar", "baz");
|
||||
verifyCompletionAtMarker("3", "foo", "bar", "baz");
|
||||
verifyCompletionAtMarker("4", "bar", "baz");
|
||||
verifyCompletionAtMarker("5");
|
||||
verifyCompletionAtMarker("6", "foo", "baz");
|
||||
verifyCompletionAtMarker("7");
|
||||
@ -0,0 +1,7 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////let v = [1,2,3,4];
|
||||
////let x = [.../**/
|
||||
|
||||
goTo.marker();
|
||||
verify.completionListContains("v");
|
||||
@ -5,9 +5,8 @@
|
||||
|
||||
////module A./*moduleName2*/
|
||||
|
||||
goTo.marker("moduleName1");
|
||||
verify.not.completionListIsEmpty();
|
||||
|
||||
test.markers().forEach((m) => {
|
||||
goTo.position(m.position, m.fileName);
|
||||
verify.not.completionListIsEmpty();
|
||||
verify.completionListAllowsNewIdentifier();
|
||||
});
|
||||
goTo.marker("moduleName2");
|
||||
verify.completionListIsEmpty();
|
||||
|
||||
39
tests/cases/fourslash/completionListInImportClause01.ts
Normal file
39
tests/cases/fourslash/completionListInImportClause01.ts
Normal file
@ -0,0 +1,39 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @Filename: m1.ts
|
||||
////export var foo: number = 1;
|
||||
////export function bar() { return 10; }
|
||||
////export function baz() { return 10; }
|
||||
|
||||
// @Filename: m2.ts
|
||||
////import {/*1*/, /*2*/ from "m1"
|
||||
////import {/*3*/} from "m1"
|
||||
////import {foo,/*4*/ from "m1"
|
||||
////import {bar as /*5*/, /*6*/ from "m1"
|
||||
////import {foo, bar, baz as b,/*7*/} from "m1"
|
||||
function verifyCompletionAtMarker(marker: string, showBuilder: boolean, ...completions: string[]) {
|
||||
goTo.marker(marker);
|
||||
if (completions.length) {
|
||||
for (let completion of completions) {
|
||||
verify.completionListContains(completion);
|
||||
}
|
||||
}
|
||||
else {
|
||||
verify.completionListIsEmpty();
|
||||
}
|
||||
|
||||
if (showBuilder) {
|
||||
verify.completionListAllowsNewIdentifier();
|
||||
}
|
||||
else {
|
||||
verify.not.completionListAllowsNewIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
verifyCompletionAtMarker("1", /*showBuilder*/ false, "foo", "bar", "baz");
|
||||
verifyCompletionAtMarker("2", /*showBuilder*/ false, "foo", "bar", "baz");
|
||||
verifyCompletionAtMarker("3", /*showBuilder*/ false, "foo", "bar", "baz");
|
||||
verifyCompletionAtMarker("4", /*showBuilder*/ false, "bar", "baz");
|
||||
verifyCompletionAtMarker("5", /*showBuilder*/ true);
|
||||
verifyCompletionAtMarker("6", /*showBuilder*/ false, "foo", "baz");
|
||||
verifyCompletionAtMarker("7", /*showBuilder*/ false);
|
||||
13
tests/cases/fourslash/completionListInImportClause02.ts
Normal file
13
tests/cases/fourslash/completionListInImportClause02.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////declare module "M1" {
|
||||
//// export var V;
|
||||
////}
|
||||
////
|
||||
////declare module "M2" {
|
||||
//// import { /**/ } from "M1"
|
||||
////}
|
||||
|
||||
goTo.marker();
|
||||
verify.completionListContains("V");
|
||||
verify.not.completionListAllowsNewIdentifier();
|
||||
6
tests/cases/fourslash/memberListAfterDoubleDot.ts
Normal file
6
tests/cases/fourslash/memberListAfterDoubleDot.ts
Normal file
@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////../**/
|
||||
|
||||
goTo.marker();
|
||||
verify.memberListIsEmpty();
|
||||
@ -3,4 +3,4 @@
|
||||
////./**/
|
||||
|
||||
goTo.marker();
|
||||
verify.not.memberListIsEmpty();
|
||||
verify.memberListIsEmpty();
|
||||
@ -3,13 +3,13 @@
|
||||
////class Foo {
|
||||
////}
|
||||
////
|
||||
////var x = class /**/Foo {
|
||||
////var x = class [|Foo|] {
|
||||
//// doIt() {
|
||||
//// return Foo;
|
||||
//// return [|Foo|];
|
||||
//// }
|
||||
////
|
||||
//// static doItStatically() {
|
||||
//// return Foo;
|
||||
//// return [|Foo|];
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
@ -23,12 +23,10 @@
|
||||
// TODO (yuit): Fix up this test when class expressions are supported.
|
||||
// Just uncomment the below, remove the marker, and add the
|
||||
// appropriate ranges in the test itself.
|
||||
goTo.marker();
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
|
||||
////let ranges = test.ranges()
|
||||
////for (let range of ranges) {
|
||||
//// goTo.position(range.start);
|
||||
////
|
||||
//// verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
////}
|
||||
let ranges = test.ranges()
|
||||
for (let range of ranges) {
|
||||
goTo.position(range.start);
|
||||
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
}
|
||||
14
tests/cases/fourslash/tsxCompletion4.ts
Normal file
14
tests/cases/fourslash/tsxCompletion4.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//@Filename: file.tsx
|
||||
//// declare namespace JSX {
|
||||
//// interface Element { }
|
||||
//// interface IntrinsicElements {
|
||||
//// div: { one; two; }
|
||||
//// }
|
||||
//// }
|
||||
//// let bag = { x: 100, y: 200 };
|
||||
//// <div {.../**/
|
||||
|
||||
goTo.marker();
|
||||
verify.completionListContains("bag");
|
||||
Loading…
x
Reference in New Issue
Block a user