Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b8082ca
Clean up jsdoc in utilities
sandersn Nov 11, 2016
641948f
Test assignability checking of object rests
sandersn Nov 16, 2016
074014e
Check assignability: rest destructuring assignment
sandersn Nov 16, 2016
eaf2f6c
Merge branch 'master' into getJSDoc-cleanup
sandersn Nov 16, 2016
3e52f3d
Codegen: Do not subtract 0 in arguments to rest array loop
subzey Nov 17, 2016
ad9ad8f
Clean up getJSDocTypeForVariableLikeDeclarationFromJSDocComment
sandersn Nov 17, 2016
5a05b94
Clean up getJSDocs
sandersn Nov 17, 2016
ddffe20
Clean up getJSDocParameterTag
sandersn Nov 17, 2016
a2b13d0
pass project name as a constructor parameter (#12333)
vladima Nov 17, 2016
e81cfa1
Clean cache code and streamline other code
sandersn Nov 17, 2016
9fec775
Merge pull request #12217 from subzey/feature/rest-loop-index
mhegazy Nov 18, 2016
2646828
Type relations for generic mapped types
ahejlsberg Nov 18, 2016
63387bb
Error on circular constraints in mapped types
ahejlsberg Nov 18, 2016
79bdc26
Accept new baselines
ahejlsberg Nov 18, 2016
075a3eb
Add new tests
ahejlsberg Nov 18, 2016
aa0d2ce
Make "exclude" default to empty if "include" is present.
Nov 18, 2016
cbde25f
Handle the scenario when heritage clause of interface is not entity n…
sheetalkamat Nov 18, 2016
2376e30
Support apparent types for T[K] indexed access types
ahejlsberg Nov 18, 2016
a789990
Add tests
ahejlsberg Nov 18, 2016
9945529
use location of config file as initial location for automatic type re…
vladima Nov 18, 2016
8674d92
Disable evolving types with implicit any
sandersn Nov 18, 2016
a4d584f
Update baselines to have no evolving types
sandersn Nov 18, 2016
aa55650
Handle when type alias's type parameter extends type that wont get em…
sheetalkamat Nov 18, 2016
e81da9c
Merge pull request #12351 from Microsoft/mappedTypeRelations
ahejlsberg Nov 18, 2016
7750fe1
Always enable evolving types in Javascript files
sandersn Nov 18, 2016
f626ff7
Merge pull request #12363 from Microsoft/declarationsInFilesWithErrors
sheetalkamat Nov 18, 2016
ab84cd0
Improve readability of types and names
sandersn Nov 18, 2016
7caee79
Rename getJSDocComments -> getCommentsFromJSDoc
sandersn Nov 18, 2016
b514d7c
Merge pull request #12362 from Microsoft/disable-evolving-types-with-…
sandersn Nov 18, 2016
91e6bce
Address PR comments
sandersn Nov 18, 2016
0c5429d
Add missed jsDoc rename in services' Node implementation
sandersn Nov 18, 2016
71b28a0
Merge pull request #12310 from Microsoft/check-object-rest-destructur…
sandersn Nov 19, 2016
eaf791e
update to tslint@next
vladima Nov 19, 2016
c96bc89
Fix issue #12260.
andraaspar Nov 19, 2016
dcd225a
Fix comparable relation for keyof T
ahejlsberg Nov 19, 2016
f2a7434
Merge pull request #12376 from Microsoft/vladima/update-tslint
vladima Nov 19, 2016
a439e62
Add tests
ahejlsberg Nov 19, 2016
4ce494a
Accept new baselines
ahejlsberg Nov 19, 2016
f8b8465
Merge pull request #12378 from andraaspar/master
mhegazy Nov 20, 2016
998246a
Merge pull request #12389 from Microsoft/keyofRelations
ahejlsberg Nov 20, 2016
110c3ac
Add locale options to tsserver (#12369)
Nov 21, 2016
7c1f33f
Fix lint errors
Nov 21, 2016
baa228b
Merge pull request #12415 from Microsoft/fix_lint
Nov 21, 2016
4092531
Merge pull request #12335 from Microsoft/getJSDoc-cleanup
sandersn Nov 21, 2016
b060107
recompute character to column when comparing indentations (#12375)
vladima Nov 21, 2016
76ceab9
Make keyof T a string-like type
ahejlsberg Nov 21, 2016
854a20f
Update Record<K, T> type
ahejlsberg Nov 21, 2016
5498a95
Update tests
ahejlsberg Nov 21, 2016
c555848
Accept new baselines
ahejlsberg Nov 21, 2016
90ee161
Merge pull request #12350 from Microsoft/default_excludes
Nov 21, 2016
4c6b94f
wrap subexpressions of conditional expressions in parens if necessary…
vladima Nov 21, 2016
1710df5
Type of for-in variable is keyof T when object type is a type parameter
ahejlsberg Nov 21, 2016
dbc661f
Accept new baselines
ahejlsberg Nov 21, 2016
b662a8b
Add test case
ahejlsberg Nov 21, 2016
77c0540
Merge pull request #12425 from Microsoft/keyofOnlyStrings
ahejlsberg Nov 21, 2016
9009da2
Update baseline-accept configuration
mhegazy Nov 22, 2016
843d08b
increase timeout
mhegazy Nov 22, 2016
5403ce6
normalize path in harness
mhegazy Nov 22, 2016
b8b6e61
handel missing files gracefully
mhegazy Nov 22, 2016
2d16b19
Merge pull request #12431 from Microsoft/rwcFixes
mhegazy Nov 22, 2016
7e8af62
Merge branch 'master' into release-2.1
mhegazy Nov 22, 2016
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
Clean cache code and streamline other code
Cache only uses one property now. getJSDocs isn't generic and doesn't
take a function parameter any more. The code is overall easier to read.
  • Loading branch information
sandersn committed Nov 17, 2016
commit e81cfa10d6c670381ee0bb9823632df34bf57ab2
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace ts {
/* @internal */ original?: Node; // The original node if this is an updated node.
/* @internal */ startsOnNewLine?: boolean; // Whether a synthesized node should start on a new line (used by transforms).
/* @internal */ jsDocComments?: JSDoc[]; // JSDoc for the node, if it has any.
/* @internal */ jsDocCache?: (JSDoc | JSDocParameterTag)[]; // JSDoc for the node, plus JSDoc retrieved from its parents
/* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding)
/* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding)
/* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding)
Expand Down
83 changes: 35 additions & 48 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,49 +1416,42 @@ namespace ts {
(<JSDocFunctionType>node).parameters[0].type.kind === SyntaxKind.JSDocConstructorType;
}

function getJSDocTag(node: Node, kind: SyntaxKind): JSDocTag {
if (!node) {
return undefined;
}

const jsDocTags = getJSDocTags(node);
if (!jsDocTags) {
return undefined;
}

for (const tag of jsDocTags) {
if (tag.kind === kind) {
return tag;
}
}
}

export function getJSDocComments(node: Node): string[] {
return getJSDocs(node, docs => map(docs, doc => doc.comment), tags => map(tags, tag => tag.comment));
return map(getJSDocs(node), doc => doc.comment);
}

function getJSDocTags(node: Node): JSDocTag[] {
return getJSDocs(node, docs => {
function getJSDocTags(node: Node, kind: SyntaxKind): JSDocTag[] {
const docs = getJSDocs(node);
if (docs) {
const result: JSDocTag[] = [];
for (const doc of docs) {
if (doc.tags) {
result.push(...doc.tags);
if (doc.kind === SyntaxKind.JSDocParameterTag) {
if (doc.kind === kind) {
result.push(doc as JSDocParameterTag);
}
}
else {
result.push(...filter((doc as JSDoc).tags, tag => tag.kind === kind));
}
}
return result;
}, tags => tags);
}
}

function getFirstJSDocTag(node: Node, kind: SyntaxKind): JSDocTag {
return node && firstOrUndefined(getJSDocTags(node, kind));
}

function getJSDocs<T>(node: Node, getContent: (docs: JSDoc[]) => T[], getContentFromParam: (tags: JSDocTag[]) => T[]): T[] {
return getJSDocsWorker(node);
function getJSDocs(node: Node): (JSDoc | JSDocParameterTag)[] {
let cache: (JSDoc | JSDocParameterTag)[] = node.jsDocCache;
if (!cache) {
getJSDocsWorker(node);
node.jsDocCache = cache;
}
return cache;

function getJSDocsWorker(node: Node) {
// TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now...
// This will be hard because it may need to cache parentvariable versions and nonparent versions
// maybe I should eliminate checkParent first ...
const parent = node.parent;
let result: T[] = undefined;

// Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement.
// /**
// * @param {number} name
Expand All @@ -1476,7 +1469,7 @@ namespace ts {
isVariableOfVariableDeclarationStatement ? parent.parent :
undefined;
if (variableStatementNode) {
result = concatenate(result, getJSDocsWorker(variableStatementNode));
getJSDocsWorker(variableStatementNode);
}

// Also recognize when the node is the RHS of an assignment expression
Expand All @@ -1486,32 +1479,26 @@ namespace ts {
(parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
parent.parent.kind === SyntaxKind.ExpressionStatement;
if (isSourceOfAssignmentExpressionStatement) {
result = concatenate(result, getJSDocsWorker(parent.parent));
getJSDocsWorker(parent.parent);
}

const isModuleDeclaration = node.kind === SyntaxKind.ModuleDeclaration &&
parent && parent.kind === SyntaxKind.ModuleDeclaration;
const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment;
if (isModuleDeclaration || isPropertyAssignmentExpression) {
result = concatenate(result, getJSDocsWorker(parent));
getJSDocsWorker(parent);
}

// Pull parameter comments from declaring function as well
if (node.kind === SyntaxKind.Parameter) {
result = concatenate(result, getContentFromParam(getJSDocParameterTag(node)));
cache = concatenate(cache, getJSDocParameterTag(node));
}

if (isVariableLike(node) && node.initializer) {
result = concatenate(result, getOwnJSDocs(node.initializer));
cache = concatenate(cache, node.initializer.jsDocComments);
}

return concatenate(result, getOwnJSDocs(node));
}

function getOwnJSDocs(node: Node) {
if (node.jsDocComments) {
return getContent(node.jsDocComments);
}
cache = concatenate(cache, node.jsDocComments);
}
}

Expand All @@ -1520,18 +1507,18 @@ namespace ts {
return undefined;
}
const func = param.parent as FunctionLikeDeclaration;
const tags = getJSDocTags(func);
const tags = getJSDocTags(func, SyntaxKind.JSDocParameterTag) as JSDocParameterTag[];
if (!param.name) {
// this is an anonymous jsdoc param from a `function(type1, type2): type3` specification
const i = func.parameters.indexOf(param);
const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag) as JSDocParameterTag[];
const paramTags = filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag);
if (paramTags && 0 <= i && i < paramTags.length) {
return [paramTags[i]];
}
}
else if (param.name.kind === SyntaxKind.Identifier) {
const name = (param.name as Identifier).text;
return filter(tags as JSDocParameterTag[], tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name);
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name);
}
else {
// TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines
Expand All @@ -1541,7 +1528,7 @@ namespace ts {
}

export function getJSDocType(node: Node): JSDocType {
let tag: JSDocTypeTag | JSDocParameterTag = getJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag;
let tag: JSDocTypeTag | JSDocParameterTag = getFirstJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag;
if (!tag && node.kind === SyntaxKind.Parameter) {
const paramTags = getJSDocParameterTag(node);
if (paramTags) {
Expand All @@ -1553,11 +1540,11 @@ namespace ts {
}

export function getJSDocReturnTag(node: Node): JSDocReturnTag {
return getJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag;
return getFirstJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag;
}

export function getJSDocTemplateTag(node: Node): JSDocTemplateTag {
return getJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag;
return getFirstJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag;
}

export function hasRestParameter(s: SignatureDeclaration): boolean {
Expand Down