Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition flattening #5332

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c5a353b
plumbing to start
weswigham Oct 8, 2015
380d881
Merge branch 'master' into definition-flattening
weswigham Oct 9, 2015
719be34
exported types can get flattened now
weswigham Oct 9, 2015
2ef2fc9
ehhh... getting there
weswigham Oct 10, 2015
cfcf245
check member visibility for type visiting, use symbol id as key
weswigham Oct 10, 2015
e57d37d
Its messy, but type flattening it here
weswigham Oct 10, 2015
ecf64ad
add a test case
weswigham Oct 12, 2015
794bd92
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 12, 2015
4516af1
Improve concatenated dts testing
weswigham Oct 12, 2015
0267d0f
old test behaviuor presrved
weswigham Oct 12, 2015
b2047f5
okay, now tests with optimization entrypoint run correctly
weswigham Oct 12, 2015
8001249
_solid_ support for type flattening
weswigham Oct 12, 2015
7f218ab
export everything
weswigham Oct 12, 2015
9ac5fa8
fix lint, accept broken scoped baselines
weswigham Oct 12, 2015
7802f22
start attempting to handle default exports
weswigham Oct 13, 2015
b8d3d9c
handling defaults correctly, now for generics
weswigham Oct 14, 2015
2d70da1
refactor a bit
weswigham Oct 14, 2015
483c7d9
handle export assignments
weswigham Oct 14, 2015
68ae4b3
more tests
weswigham Oct 14, 2015
3625990
Type walk is pretty beatuiful now, still not exporting aliases right,…
weswigham Oct 15, 2015
8a04d40
i now know whye everyone hates self referential type aliases
weswigham Oct 15, 2015
b08dc4e
changeup traversal a bit, still cant do aliases or type queries right
weswigham Oct 15, 2015
818b89b
We now find higher level declarations for nested types so typeof expr…
weswigham Oct 17, 2015
2e1bcce
move comments
weswigham Oct 17, 2015
0d6c194
break early on export =, not that there should be toher declarations
weswigham Oct 17, 2015
066ffa9
Fix things, awwww yis
weswigham Oct 17, 2015
4d66987
collect declarations to begin with, rather than types
weswigham Oct 19, 2015
93eee77
re-correct the name mangling of default exports
weswigham Oct 19, 2015
39abdb6
lint fixes
weswigham Oct 19, 2015
63a9673
accept new test baselines
weswigham Oct 20, 2015
3f2414b
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 20, 2015
3aada13
Add a test with export default expressions and types from dtses
weswigham Oct 20, 2015
84ec5bf
note: the last file in a test cannot be a dts or badness ensues
weswigham Oct 20, 2015
9284aea
handles export assignment expressions correctly now
weswigham Oct 20, 2015
a50f078
move some bits around which fixes a test
weswigham Oct 20, 2015
40a42a2
Meh is unbecomingish
weswigham Oct 20, 2015
a2d93fe
imports are awesome
weswigham Oct 20, 2015
f14091e
add triple slash refs to test
weswigham Oct 20, 2015
c67cff8
Add node_modules test
weswigham Oct 20, 2015
d7f7385
handles module identifiers
weswigham Oct 20, 2015
c0c02dd
small fix, accept new baselines
weswigham Oct 20, 2015
a5b9e3a
handles export assignments in imports
weswigham Oct 20, 2015
8088ebe
accept new baselines
weswigham Oct 20, 2015
59b8fa3
fix lint
weswigham Oct 20, 2015
cccec7d
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 20, 2015
1f096fc
move return
weswigham Oct 20, 2015
99546f0
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 20, 2015
fab4584
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 21, 2015
c9e004a
remove extra member, move diagnostics to program
weswigham Oct 21, 2015
ef5075b
use side table for identifiers
weswigham Oct 22, 2015
cc7a734
derive import equals name from module name
weswigham Oct 22, 2015
197028c
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 22, 2015
e6b1ae8
fixup the bits, add another test, and accpt the new baselines
weswigham Oct 22, 2015
5d6b1d5
typeWalker -> symbolWalker, handle type queries better
weswigham Oct 23, 2015
439bb9e
Accept new baseline
weswigham Oct 23, 2015
06eea16
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 30, 2015
608955a
comma
weswigham Oct 30, 2015
e77a05a
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 30, 2015
dbb913e
semicolong
weswigham Oct 30, 2015
49fe17a
Merge branch 'out-module-concat' into definition-flattening
weswigham Oct 30, 2015
60fb963
Merge branch 'out-module-concat' into definition-flattening
weswigham Nov 2, 2015
74db034
Merge branch 'out-module-concat' into definition-flattening
weswigham Nov 3, 2015
f354b91
add back in methods
weswigham Nov 3, 2015
f17efbd
fix with changes since merge, accept new baselines
weswigham Nov 3, 2015
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
177 changes: 175 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ namespace ts {

getJsxElementAttributesType,
getJsxIntrinsicTagNames,
isOptionalParameter
isOptionalParameter,
getSymbolWalker
};

let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
Expand Down Expand Up @@ -2052,6 +2053,164 @@ namespace ts {
});
}

function getSymbolWalker(accept: (symbol: Symbol) => boolean = () => true): SymbolWalker {
let visited: Type[] = [];
let visitedSymbols: Symbol[] = [];

return {
visitType,
visitTypeFromSymbol,
reset: (newCallback: (symbol: Symbol) => boolean = () => true) => {
accept = newCallback;
visited = [];
visitedSymbols = [];
}
};

function visitType(type: Type): void {
if (!type) {
return;
}
if (contains(visited, type)) {
return;
}
visited.push(type);
if (type.symbol) {
if (!accept(type.symbol)) {
return;
}
}

// Visit the type's related types, if any
if (type.flags & TypeFlags.Reference) {
visitTypeReference(type as TypeReference);
}
if (type.flags & TypeFlags.TypeParameter) {
visitTypeParameter(type as TypeParameter);
}
if (type.flags & TypeFlags.Tuple) {
visitTupleType(type as TupleType);
}
if (type.flags & TypeFlags.UnionOrIntersection) {
visitUnionOrIntersectionType(type as UnionOrIntersectionType);
}
if (type.flags & (TypeFlags.Class | TypeFlags.Interface)) {
visitInterfaceType(type as InterfaceType);
}
if (type.flags & TypeFlags.Anonymous) {
visitObjectType(type as ObjectType);
}
}

function visitTypeList(types: Type[]): void {
if (!types) {
return;
}
for (let i = 0; i < types.length; i++) {
visitType(types[i]);
}
}

function visitTypeReference(type: TypeReference): void {
visitType(type.target);
let typeArguments: Type[] = type.typeArguments || emptyArray;
if (type.target === globalArrayType) { // Shortcut
visitType(typeArguments[0]);
}
else {
visitTypeList(typeArguments);
}
}

function visitTypeParameter(type: TypeParameter): void {
visitType(type.constraint);
}

function visitTupleType(type: TupleType): void {
visitTypeList(type.elementTypes);
}

function visitUnionOrIntersectionType(type: UnionOrIntersectionType): void {
visitTypeList(type.types);
}

function visitSignature(signature: Signature): void {
if (signature.typePredicate) {
visitType(signature.typePredicate.type);
}
visitTypeList(signature.typeParameters);

for (let parameter of signature.parameters){
visitTypeFromSymbol(parameter);
}
visitType(getRestTypeOfSignature(signature));
visitType(getReturnTypeOfSignature(signature));
}

function visitInterfaceType(interfaceT: InterfaceType): void {
visitObjectType(interfaceT);
if (interfaceT.typeParameters) {
visitTypeList(interfaceT.typeParameters);
}
visitTypeList(getBaseTypes(interfaceT));
visitType(interfaceT.thisType);
}

function visitObjectType(type: ObjectType): void {
let resolved = resolveStructuredTypeMembers(type);

if (resolved.stringIndexType) {
visitType(resolved.stringIndexType);
}
if (resolved.numberIndexType) {
visitType(resolved.numberIndexType);
}
for (let signature of resolved.callSignatures) {
visitSignature(signature);
}
for (let signature of resolved.constructSignatures) {
visitSignature(signature);
}
for (let p of resolved.properties) {
visitTypeFromSymbol(p);
}
}

function visitTypeFromSymbol(symbol: Symbol): void {
if (contains(visitedSymbols, symbol)) {
return;
}
visitedSymbols.push(symbol);
if (!accept(symbol)) {
return;
}
let t = getTypeOfSymbol(symbol);
visitType(t); // Should handle members on classes and such
if (symbol.flags & SymbolFlags.HasExports) {
forEachValue(symbol.exports, visitTypeFromSymbol);
}
forEach(symbol.declarations, d => {
// Type queries are too far resolved when we just visit the symbol's type
// So to get the intervening symbols, we need to check if there's a type
// query node on any of the symbol's declarations and get symbols there
if ((d as any).type && (d as any).type.kind === SyntaxKind.TypeQuery) {
let query = (d as any).type as TypeQueryNode;
let entity = leftmostSymbol(query.exprName);
visitTypeFromSymbol(entity);
}
});

function leftmostSymbol(expr: QualifiedName | Identifier): Symbol {
if (expr.kind === SyntaxKind.Identifier) {
return getResolvedSymbol(expr as Identifier);
}
else {
return leftmostSymbol((expr as QualifiedName).left);
}
}
}
}

function isDeclarationVisible(node: Declaration): boolean {
function getContainingExternalModule(node: Node) {
for (; node; node = node.parent) {
Expand Down Expand Up @@ -14900,8 +15059,22 @@ namespace ts {
getReferencedValueDeclaration,
getTypeReferenceSerializationKind,
isOptionalParameter,
getExportsOfModule: getExportsOfModuleAsArray,
getDefiningTypeOfSymbol: (symbol: Symbol) => {
let declaredType = getDeclaredTypeOfSymbol(symbol);
if (declaredType !== unknownType) {
return declaredType;
}
let valueType = getTypeOfSymbol(symbol);
if (valueType !== unknownType) {
return valueType;
}
},
resolveEntityName,
getSymbolWalker,
isArgumentsLocalBinding,
getExternalModuleFileFromDeclaration
getExternalModuleFileFromDeclaration,
getSymbolAtLocation,
};
}

Expand Down
7 changes: 7 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ namespace ts {
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic,
},
{
name: "optimizationEntrypoint",
type: "string",
isFilePath: true,
description: Diagnostics.Specifies_the_script_file_used_as_the_entrypoint_for_optimizations,
paramType: Diagnostics.FILE
},
{
name: "allowUnusedLabels",
type: "boolean",
Expand Down
Loading