(bugfix) extract strings encapsulated with backticks. Closes #139
This commit is contained in:
		| @@ -4,7 +4,8 @@ import { | ||||
| 	CallExpression, | ||||
| 	Node, | ||||
| 	SyntaxKind, | ||||
| 	StringLiteral | ||||
| 	StringLiteral, | ||||
| 	NoSubstitutionTemplateLiteral | ||||
| } from 'typescript'; | ||||
|  | ||||
| export abstract class AbstractAstParser { | ||||
| @@ -24,19 +25,23 @@ export abstract class AbstractAstParser { | ||||
| 		} | ||||
|  | ||||
| 		const firstArg = callNode.arguments[0]; | ||||
| 		return this.findNodes(firstArg, SyntaxKind.StringLiteral) | ||||
| 			.map((node: StringLiteral) => node.text); | ||||
|  | ||||
| 		return this.findNodes(firstArg, [ | ||||
| 			SyntaxKind.StringLiteral, | ||||
| 			SyntaxKind.NoSubstitutionTemplateLiteral | ||||
| 		]) | ||||
| 		.map((node: StringLiteral | NoSubstitutionTemplateLiteral) => node.text); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Find all child nodes of a kind | ||||
| 	 */ | ||||
| 	protected findNodes(node: Node, kind: SyntaxKind): Node[] { | ||||
| 	protected findNodes(node: Node, kinds: SyntaxKind[]): Node[] { | ||||
| 		const childrenNodes: Node[] = node.getChildren(this.sourceFile); | ||||
| 		const initialValue: Node[] = node.kind === kind ? [node] : []; | ||||
| 		const initialValue: Node[] = kinds.includes(node.kind) ? [node] : []; | ||||
|  | ||||
| 		return childrenNodes.reduce((result: Node[], childNode: Node) => { | ||||
| 			return result.concat(this.findNodes(childNode, kind)); | ||||
| 			return result.concat(this.findNodes(childNode, kinds)); | ||||
| 		}, initialValue); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -38,7 +38,7 @@ export class FunctionParser extends AbstractAstParser implements ParserInterface | ||||
| 			node = this.sourceFile; | ||||
| 		} | ||||
|  | ||||
| 		let callNodes = this.findNodes(node, SyntaxKind.CallExpression) as CallExpression[]; | ||||
| 		let callNodes = this.findNodes(node, [SyntaxKind.CallExpression]) as CallExpression[]; | ||||
| 		callNodes = callNodes | ||||
| 			.filter(callNode => { | ||||
| 				// Only call expressions with arguments | ||||
|   | ||||
| @@ -89,14 +89,14 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface | ||||
| 	 * Find class nodes | ||||
| 	 */ | ||||
| 	protected findClassNodes(node: Node): ClassDeclaration[] { | ||||
| 		return this.findNodes(node, SyntaxKind.ClassDeclaration) as ClassDeclaration[]; | ||||
| 		return this.findNodes(node, [SyntaxKind.ClassDeclaration]) as ClassDeclaration[]; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Find constructor | ||||
| 	 */ | ||||
| 	protected findConstructorNode(node: ClassDeclaration): ConstructorDeclaration { | ||||
| 		const constructorNodes = this.findNodes(node, SyntaxKind.Constructor) as ConstructorDeclaration[]; | ||||
| 		const constructorNodes = this.findNodes(node, [SyntaxKind.Constructor]) as ConstructorDeclaration[]; | ||||
| 		if (constructorNodes) { | ||||
| 			return constructorNodes[0]; | ||||
| 		} | ||||
| @@ -106,7 +106,7 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface | ||||
| 	 * Find all calls to TranslateService methods | ||||
| 	 */ | ||||
| 	protected findCallNodes(node: Node, propertyIdentifier: string): CallExpression[] { | ||||
| 		let callNodes = this.findNodes(node, SyntaxKind.CallExpression) as CallExpression[]; | ||||
| 		let callNodes = this.findNodes(node, [SyntaxKind.CallExpression]) as CallExpression[]; | ||||
| 		callNodes = callNodes | ||||
| 			.filter(callNode => { | ||||
| 				// Only call expressions with arguments | ||||
|   | ||||
		Reference in New Issue
	
	Block a user