-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
545 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ tslint.yaml | |
|
||
# Tests | ||
dist/**/*.spec.* | ||
dist/test/ | ||
|
||
# Coverage | ||
.nyc_output/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"printWidth": 108, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { basename, join } from 'path' | ||
import { Expression } from 'typescript' | ||
|
||
/** | ||
* Asset module manager can be used to detect asset modules and build a module name from a module | ||
* specifier. | ||
*/ | ||
export default class AssetModuleManager { | ||
/** | ||
* Create the object. | ||
* | ||
* @param assetsMatch - The regular expression for detecting matching modules. | ||
* @param targetPath - The public target path for the assets. | ||
*/ | ||
public constructor(private assetsMatch: RegExp, private targetPath?: string) {} | ||
|
||
/** | ||
* Build the module name as it should be used inside source file, if the module specifier matches the | ||
* given `assetsMatch`. | ||
* | ||
* @param moduleSpecifier - The module specifier. | ||
* @returns The build module name or undefined if not matching. | ||
*/ | ||
public buildName(moduleSpecifier?: Expression): string | undefined { | ||
if (moduleSpecifier) { | ||
// Remove quotes for name | ||
let moduleName: string = moduleSpecifier.getText() | ||
moduleName = moduleName.substring(1, moduleName.length - 1) | ||
|
||
// Check if matching assets pattern | ||
if (this.assetsMatch.test(moduleName)) { | ||
// Convert file name | ||
moduleName = basename(moduleName) | ||
this.targetPath && (moduleName = join(this.targetPath, moduleName)) | ||
return moduleName | ||
} | ||
} | ||
return undefined | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Identifier, Node, TypeChecker } from 'typescript' | ||
|
||
/** | ||
* An object searching for a declaration node for a given identifier. | ||
*/ | ||
export default class DeclarationNodeFinder { | ||
/** | ||
* Create the object. | ||
* | ||
* @param typeChecker - The type checker. | ||
*/ | ||
public constructor(public typeChecker: TypeChecker) {} | ||
|
||
/** | ||
* Search for the declaration node of a given identifier. | ||
* | ||
* @param node - The node to search declaration for. | ||
* @returns The declaration node if found, undefined otherwise. | ||
*/ | ||
public find(node: Identifier): Node | undefined { | ||
const symbol = this.typeChecker.getSymbolAtLocation(node) | ||
if (symbol) { | ||
const declarations = symbol.getDeclarations() | ||
if (declarations && declarations.length === 1) { | ||
return declarations[0] | ||
} | ||
} | ||
return undefined | ||
} | ||
} |
Oops, something went wrong.