Skip to content

Commit

Permalink
NPM Release 1.2.0.rc-8
Browse files Browse the repository at this point in the history
Addresses issues #71, #66, #65
  • Loading branch information
ToddThomson committed Feb 5, 2016
1 parent 0697f04 commit 5966f90
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 77 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ TsProject produces a compiled output stream of vinyl files for further processin

TsProject 1.2.0 provides bundle minification by shortening identifiers and whitespace removal.

TsProject 1.2.0 provides bundle packaging support for library and component types.

TsProject 1.1.0 provides project watch support for cache optimized, incremental builds.

TsProject 1.1.0 supports Typescript 1.7!
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsproject",
"version": "1.2.0-rc.7",
"version": "1.2.0-rc.8",
"description": "Typescript project compiler and modular typescript bundle optimizer for gulp (Ts Vinyl Adapter).",
"homepage": "https://github.com/toddthomson/tsproject",
"bugs": "https://github.com/toddthomson/tsproject/issues",
Expand All @@ -23,7 +23,7 @@
"run-sequence": "^1.1.5",
"tsd": "^0.6.5",
"typescript": "^1.7.5",
"tsproject": "^1.2.0-rc.7",
"tsproject": "^1.2.0-rc.8",
"vinyl-paths": "^2.1.0"
},
"scripts": {
Expand Down
60 changes: 6 additions & 54 deletions src/Minifier/BundleMinifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,14 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
if ( this.compilerOptions.diagnostics )
this.reportWhitespaceStatistics();

return jsContents; //output;
return output;
}

protected visitNode( node: ts.Node ): void {
// Traverse nodes to build containers and process all identifiers nodes.
if ( this.isNextContainer( node ) ) {
Logger.trace( ">>> Scanning container for identifiers: ", this.currentContainer().getId() );

super.visitNode( node );

Logger.trace( "<<< Done. Scanning container for identifiers: ", this.currentContainer().getId() );
this.restoreContainer();
}
else {
Expand All @@ -214,10 +211,6 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
if ( identifierSymbol ) {
let identifierUID = Ast.getIdentifierUID( identifierSymbol );

if (identifierSymbol.name === "setInterval" ) {
Logger.log( "break" );
}

if ( identifierUID === undefined ) {
if ( identifierSymbol.flags & ts.SymbolFlags.Transient ) {
// TJT: Can we ignore all transient symbols?
Expand All @@ -230,11 +223,8 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
}
}

Logger.trace( "Identifier found: ", identifierSymbol.name, identifierUID );

// Check to see if we've seen this identifer symbol before
if ( Utils.hasProperty( this.allIdentifierInfos, identifierUID ) ) {
Logger.trace( "Identifier has already been added: ", identifierSymbol.name );
// If we have, then add it to the identifier info references
let prevAddedIdentifier = this.allIdentifierInfos[ identifierUID ];
this.allIdentifierInfos[ identifierUID ].addRef( identifier, this.currentContainer() );
Expand All @@ -246,7 +236,6 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
}
}
else {
Logger.trace( "Adding new identifier symbol." );
let identifierInfo = new IdentifierInfo( identifier, identifierSymbol, this.currentContainer() );

// Add the new identifier info to both the container and the all list
Expand All @@ -271,10 +260,6 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
}

break;

//default:
// // TJT: Remove after testing
// Logger.trace( "Non identifier node: ", node.kind );
}

super.visitNode( node );
Expand Down Expand Up @@ -331,13 +316,10 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
}

private shortenContainerIdentifiers( container: Container ): void {
Logger.trace( ">>> shortenContainerIdentifiers(): ", container.getId() );

// If this container extends a base/parent class then we must make sure we have processed the base/parent class members
let baseClass = container.getBaseClass();

if ( baseClass ) {
Logger.trace( ">>> Processing inherited base class members..." );
// We need to get the container for the parent/base class
let baseClassContainer = this.classifiableContainers[ baseClass.name ];

Expand All @@ -347,31 +329,25 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
this.processClassMembers( baseClassMembers, baseClassContainer );
}
}
Logger.trace( "<<< Done. Processing inherited base class members" );
}

Logger.trace( ">>> Determining container excluded names..." );

// Determine the names which cannot be used as shortened names in this container.
this.excludeNames( container );
Logger.trace( "<<< Done. Determining container excluded names" );

// Process container members..
let containerClassMembers = container.getMembers();
if ( containerClassMembers ) {
Logger.trace( ">>> Processing container class members..." );
this.processClassMembers( containerClassMembers, container );
Logger.trace( "<<< Done. Processing inherited base class members" );
}

// Process container locals..
let containerLocals = container.getLocals();
if ( containerLocals ) {
Logger.trace( ">>> Processing container locals.." );
this.processContainerLocals( containerLocals, container );
Logger.trace( "<<< Done. Processing container locals." );
}

// Process the containers identifiers...
Logger.trace( "Processing container local symbols..." );
for ( let identifierTableKey in container.localIdentifiers ) {
let identifierInfo = container.localIdentifiers[identifierTableKey];

Expand All @@ -382,7 +358,6 @@ export class BundleMinifier extends NodeWalker implements AstTransform {

// TJT: Review..

Logger.trace( "Processing container classifiables..." );
for ( let classifiableKey in container.classifiableSymbols ) {
let classSymbol = container.classifiableSymbols[ classifiableKey ];

Expand All @@ -392,24 +367,15 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
this.processIdentifierInfo( classIdentifierInfo, container );
}

Logger.trace( ">>> Processing container children..." );
// Recursively go through container children in order added
let containerChildren = container.getChildren();

for ( let j = 0; j < containerChildren.length; j++ ) {
this.shortenContainerIdentifiers( containerChildren[j] );
}
Logger.trace( "<<< Done. Processing container children" );

Logger.trace( "<<< Done. shortenContainerIdentifiers(): ", container.getId() );
}

private processIdentifierInfo( identifierInfo: IdentifierInfo, container: Container ): void {

if (identifierInfo.getSymbol().name === "setInterval" ) {
Logger.log( "break" );
}

if ( this.canShortenIdentifier( identifierInfo ) ) {
let shortenedName = this.getShortenedIdentifierName( container, identifierInfo );

Expand Down Expand Up @@ -439,7 +405,8 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
identifierInfo.isPrivateMethod() ||
identifierInfo.isPrivateProperty() ||
identifierInfo.isInternalFunction( this.bundleConfig.package.getPackageNamespace() ) ||
identifierInfo.isParameter() ) {
identifierInfo.isParameter() ||
identifierInfo.isNamespaceImportAlias() ) {

Logger.trace( "Identifier CAN be shortened: ", identifierInfo.getName() );
return true;
Expand Down Expand Up @@ -557,13 +524,10 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
public excludeNames( container: Container ): void {
// Determine identifier names which cannot be used in this container.

Logger.trace( ">>> Excluding names for container id: ", container.getId() );

// If this container extends a base/parent class then we exclude the base class member names.
let baseClass = container.getBaseClass();

if ( baseClass ) {
Logger.trace( ">>> Excluding base class members..." );

// We need to get the container for the parent/base class
let baseClassContainer = this.classifiableContainers[ baseClass.name ];
Expand All @@ -580,22 +544,18 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
let excludedSymbol = this.allIdentifierInfos[ memberSymbolUId ] ;

if ( excludedSymbol && excludedSymbol.shortenedName ) {
Logger.trace( "Excluding identifier name for: ", excludedSymbol.getName(), excludedSymbol.shortenedName );
container.namesExcluded[ excludedSymbol.shortenedName ] = true;
}
}
}
}
Logger.trace( "<<< Done. Excluding base class members" );
}

Logger.trace( "Excluding container locals..." );
for ( let identifierInfoKey in container.localIdentifiers ) {
let identifierInfo = container.localIdentifiers[ identifierInfoKey ];

this.excludeNamesForIdentifier( identifierInfo, container );
}
Logger.trace( "Excluding container classifiables..." );

for ( let classifiableKey in container.classifiableSymbols ) {
let classSymbol = container.classifiableSymbols[ classifiableKey ];
Expand All @@ -607,7 +567,6 @@ export class BundleMinifier extends NodeWalker implements AstTransform {

this.excludeNamesForIdentifier( classIdentifierInfo, container );
}
Logger.trace( "<<< Done. Excluding names for container id: ", container.getId() );
}

private getContainerExcludedIdentifiers( container: Container ): ts.Map<IdentifierInfo> {
Expand Down Expand Up @@ -649,8 +608,6 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
}

private excludeNamesForIdentifier( identifierInfo: IdentifierInfo, container: Container ): void {
Logger.trace( ">>> Excluding names for identifier: ", identifierInfo.getName() );

// Exclude all shortened names that have already been used in child containers that this identifer is contained in.
let identifierContainers = identifierInfo.getContainers();

Expand All @@ -666,11 +623,9 @@ export class BundleMinifier extends NodeWalker implements AstTransform {

if ( excludedIdentifier.shortenedName ) {
container.namesExcluded[ excludedIdentifier.shortenedName ] = true;
Logger.trace( "Excluding identifier name: ", excludedIdentifier.shortenedName );
}
}
}
Logger.trace( "<<< Done. Excluding names for identifier: ", identifierInfo.getName() );
}

private currentContainer(): Container {
Expand Down Expand Up @@ -713,9 +668,7 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
// If this child class is declared before the parent base class then the base class symbol will have symbolFlags.Merged.
// When the base class is declared it will have a different symbol id from the symbol id determined here.
// We should be able to use the symbol name for lookups in the classifiable containers table.
//let baseClassAlias = this.checker.getAliasedSymbol(baseClassSymbol);

Logger.trace( "Extending base class: ", baseClassSymbol.name );
// let baseClassAlias = this.checker.getAliasedSymbol(baseClassSymbol);

nextContainer.setBaseClass( baseClassSymbol );
}
Expand Down Expand Up @@ -754,6 +707,5 @@ export class BundleMinifier extends NodeWalker implements AstTransform {
statisticsReporter.reportTime( "Minify time", this.transformTime );
statisticsReporter.reportCount( "Total identifiers", this.identifierCount );
statisticsReporter.reportCount( "Identifiers shortened", this.shortenedIdentifierCount );
//statisticsReporter.reportPercentage( "shortened", ( ( this.IdentifierSpaceBefore - this.whiteSpaceAfter ) / this.whiteSpaceBefore ) * 100.00 );
}
}
2 changes: 0 additions & 2 deletions src/Minifier/ContainerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ export class Container {
this.containerFlags = containerFlags;

if ( containerFlags & Ast.ContainerFlags.IsBlockScopedContainer ) {
Logger.trace( "Container is BlockScoped" );
this.blockScopeContainer = node;
this.isBlockScope = true;

// A block scoped container's parent is the parent function scope container.
this.parent = parentContainer.getParent();
}
else {
Logger.trace( "Container is FunctionScoped" );
this.container = this.blockScopeContainer = node;
this.isBlockScope = false;

Expand Down
39 changes: 23 additions & 16 deletions src/Minifier/IdentifierSymbolInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class IdentifierInfo {
}

public addRef( identifier: ts.Identifier, container: Container ): void {
Logger.trace( "Adding identifier ref: ", container.getId(), this.getName() );
// Add the identifier (node) reference
this.identifiers.push( identifier );

Expand All @@ -58,6 +57,16 @@ export class IdentifierInfo {
}
}

public isNamespaceImportAlias(): boolean {
if ( ( this.symbol.flags & ts.SymbolFlags.Alias ) > 0 ) {
if ( this.symbol.declarations[0].kind === ts.SyntaxKind.NamespaceImport ) {
return true;
}
}

return false;
}

public isFunctionScopedVariable(): boolean {
if ( ( this.symbol.flags & ts.SymbolFlags.FunctionScopedVariable ) > 0 ) {
let variableDeclaration = this.getVariableDeclaration();
Expand All @@ -83,19 +92,6 @@ export class IdentifierInfo {
return false;
}

public isParameter(): boolean {
// Note: FunctionScopedVariable also indicates a parameter
if ( ( this.symbol.flags & ts.SymbolFlags.FunctionScopedVariable ) > 0 ) {

// A parameter has a value declaration
if ( this.symbol.valueDeclaration.kind === ts.SyntaxKind.Parameter ) {
return true;
}
}

return false;
}

public isInternalFunction( packageNamespace: string ): boolean {
if ( this.symbol.flags & ts.SymbolFlags.Function ) {

Expand Down Expand Up @@ -132,6 +128,19 @@ export class IdentifierInfo {
return false;
}

public isParameter(): boolean {
// Note: FunctionScopedVariable also indicates a parameter
if ( ( this.symbol.flags & ts.SymbolFlags.FunctionScopedVariable ) > 0 ) {

// A parameter has a value declaration
if ( this.symbol.valueDeclaration.kind === ts.SyntaxKind.Parameter ) {
return true;
}
}

return false;
}

public isInternalClass(): boolean {

// TJT: Review - should use the same export "override" logic as in isInternalFunction
Expand Down Expand Up @@ -207,6 +216,4 @@ export class IdentifierInfo {

return null;
}


}
2 changes: 0 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
"config": {
"package": "component",
"packageNamespace": "TsProject",
"declaration": false,
"sourceMap": false,
"outDir": "./bundle",
"minify": true
}
Expand Down
2 changes: 1 addition & 1 deletion tsproject.min.js

Large diffs are not rendered by default.

0 comments on commit 5966f90

Please sign in to comment.