Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
64ebb5e6e8 | ||
|
40051f4144 | ||
|
14eb09f947 | ||
|
8d1e2c5a2f | ||
|
4892ea5146 | ||
|
ee28fe2a64 | ||
|
7c06b66974 | ||
|
b2ae17697d | ||
|
5259da8fe3 | ||
|
2d73f056ff | ||
|
fde5245731 | ||
|
4ee7258a31 | ||
|
a6c7af0630 | ||
|
0949bf765b | ||
|
d416c6b9fd | ||
|
4e351405fb | ||
|
39a335638b | ||
|
3b9561916b | ||
|
5cef383f3b | ||
|
677d2a35ca | ||
|
262a89206d | ||
|
bcb4a9c069 | ||
|
5ad1fe6a18 | ||
|
bc5ce7e80d | ||
|
030ab145d6 | ||
|
daaebede6f |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -10,8 +10,8 @@ npm-debug.log*
|
|||||||
dist
|
dist
|
||||||
|
|
||||||
# Extracted strings
|
# Extracted strings
|
||||||
template.json
|
strings.json
|
||||||
template.pot
|
strings.pot
|
||||||
|
|
||||||
# Dependency directory
|
# Dependency directory
|
||||||
node_modules
|
node_modules
|
||||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Kim Biesbjerg
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
16
README.md
16
README.md
@@ -50,6 +50,18 @@ If you want to use spaces instead, you can do the following:
|
|||||||
|
|
||||||
`ngx-translate-extract -i ./src -o ./src/i18n/en.json --format-indentation ' '`
|
`ngx-translate-extract -i ./src -o ./src/i18n/en.json --format-indentation ' '`
|
||||||
|
|
||||||
|
## Mark strings for extraction using a marker function
|
||||||
|
If, for some reason, you want to extract strings not passed directly to TranslateService, you can wrap them in a custom marker function.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { _ } from '@biesbjerg/ngx-translate-extract';
|
||||||
|
|
||||||
|
_('Extract me');
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the `marker` argument when running the extract script:
|
||||||
|
|
||||||
|
`ngx-translate-extract ... -m _`
|
||||||
|
|
||||||
Modify the scripts arguments as required.
|
Modify the scripts arguments as required.
|
||||||
|
|
||||||
@@ -70,6 +82,8 @@ Options:
|
|||||||
--output, -o Paths where you would like to save extracted
|
--output, -o Paths where you would like to save extracted
|
||||||
strings. You can use path expansion, glob patterns
|
strings. You can use path expansion, glob patterns
|
||||||
and multiple paths [array] [required]
|
and multiple paths [array] [required]
|
||||||
|
--marker, -m Extract strings passed to a marker function
|
||||||
|
[string] [default: false]
|
||||||
--format, -f Output format
|
--format, -f Output format
|
||||||
[string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
|
[string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
|
||||||
--format-indentation, --fi Output format indentation [string] [default: "\t"]
|
--format-indentation, --fi Output format indentation [string] [default: "\t"]
|
||||||
@@ -79,3 +93,5 @@ Options:
|
|||||||
[boolean] [default: false]
|
[boolean] [default: false]
|
||||||
--clean, -c Remove obsolete strings when merging
|
--clean, -c Remove obsolete strings when merging
|
||||||
[boolean] [default: false]
|
[boolean] [default: false]
|
||||||
|
--verbose, -vb If true, prints all processed file paths to console
|
||||||
|
[boolean] [default: true]
|
||||||
|
1278
package-lock.json
generated
Normal file
1278
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@biesbjerg/ngx-translate-extract",
|
"name": "@biesbjerg/ngx-translate-extract",
|
||||||
"version": "2.1.0",
|
"version": "2.3.4",
|
||||||
"description": "Extract strings from projects using ngx-translate",
|
"description": "Extract strings from projects using ngx-translate",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@@ -47,30 +47,30 @@
|
|||||||
},
|
},
|
||||||
"config": {},
|
"config": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "3.4.35",
|
"@types/chai": "4.0.1",
|
||||||
"@types/glob": "5.0.30",
|
"@types/glob": "5.0.30",
|
||||||
"@types/mocha": "2.2.40",
|
"@types/mocha": "2.2.41",
|
||||||
"@types/cheerio": "0.22.1",
|
"@types/cheerio": "0.22.1",
|
||||||
"@types/chalk": "0.4.31",
|
"@types/chalk": "0.4.31",
|
||||||
"@types/flat": "0.0.28",
|
"@types/flat": "0.0.28",
|
||||||
"@types/yargs": "6.6.0",
|
"@types/yargs": "8.0.0",
|
||||||
"@types/mkdirp": "0.3.29",
|
"@types/mkdirp": "0.3.29",
|
||||||
"chai": "3.5.0",
|
"chai": "4.0.2",
|
||||||
"mocha": "3.2.0",
|
"mocha": "3.4.2",
|
||||||
"ts-node": "3.0.2",
|
"ts-node": "3.1.0",
|
||||||
"tslint": "4.5.1",
|
"tslint": "5.4.3",
|
||||||
"tslint-eslint-rules": "3.5.1",
|
"tslint-eslint-rules": "4.1.1"
|
||||||
"typescript": "2.2.2"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "1.1.3",
|
"chalk": "2.0.1",
|
||||||
"yargs": "7.0.2",
|
"yargs": "8.0.2",
|
||||||
"cheerio": "0.22.0",
|
"cheerio": "1.0.0-rc.2",
|
||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"gettext-parser": "1.2.2",
|
"gettext-parser": "1.2.2",
|
||||||
"glob": "7.1.1",
|
"glob": "7.1.2",
|
||||||
"path": "0.12.7",
|
"path": "0.12.7",
|
||||||
"mkdirp": "0.5.1",
|
"mkdirp": "0.5.1",
|
||||||
"flat": "2.0.1"
|
"flat": "2.0.1",
|
||||||
|
"typescript": "2.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ import { ParserInterface } from '../parsers/parser.interface';
|
|||||||
import { PipeParser } from '../parsers/pipe.parser';
|
import { PipeParser } from '../parsers/pipe.parser';
|
||||||
import { DirectiveParser } from '../parsers/directive.parser';
|
import { DirectiveParser } from '../parsers/directive.parser';
|
||||||
import { ServiceParser } from '../parsers/service.parser';
|
import { ServiceParser } from '../parsers/service.parser';
|
||||||
|
import { FunctionParser } from '../parsers/function.parser';
|
||||||
import { CompilerInterface } from '../compilers/compiler.interface';
|
import { CompilerInterface } from '../compilers/compiler.interface';
|
||||||
import { CompilerFactory } from '../compilers/compiler.factory';
|
import { CompilerFactory } from '../compilers/compiler.factory';
|
||||||
|
|
||||||
@@ -44,6 +45,12 @@ export const cli = yargs
|
|||||||
normalize: true,
|
normalize: true,
|
||||||
required: true
|
required: true
|
||||||
})
|
})
|
||||||
|
.option('marker', {
|
||||||
|
alias: 'm',
|
||||||
|
describe: 'Extract strings passed to a marker function',
|
||||||
|
default: false,
|
||||||
|
type: 'string'
|
||||||
|
})
|
||||||
.option('format', {
|
.option('format', {
|
||||||
alias: 'f',
|
alias: 'f',
|
||||||
describe: 'Output format',
|
describe: 'Output format',
|
||||||
@@ -75,25 +82,37 @@ export const cli = yargs
|
|||||||
default: false,
|
default: false,
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
})
|
})
|
||||||
|
.option('verbose', {
|
||||||
|
alias: 'vb',
|
||||||
|
describe: 'Log all output to console',
|
||||||
|
default: true,
|
||||||
|
type: 'boolean'
|
||||||
|
})
|
||||||
.exitProcess(true)
|
.exitProcess(true)
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
const parsers: ParserInterface[] = [
|
const extract = new ExtractTask(cli.input, cli.output, {
|
||||||
new ServiceParser(),
|
|
||||||
new PipeParser(),
|
|
||||||
new DirectiveParser()
|
|
||||||
];
|
|
||||||
|
|
||||||
const compiler: CompilerInterface = CompilerFactory.create(cli.format, {
|
|
||||||
indentation: cli.formatIndentation
|
|
||||||
});
|
|
||||||
|
|
||||||
new ExtractTask(cli.input, cli.output, {
|
|
||||||
replace: cli.replace,
|
replace: cli.replace,
|
||||||
sort: cli.sort,
|
sort: cli.sort,
|
||||||
clean: cli.clean,
|
clean: cli.clean,
|
||||||
patterns: cli.patterns
|
patterns: cli.patterns
|
||||||
})
|
});
|
||||||
.setParsers(parsers)
|
|
||||||
.setCompiler(compiler)
|
const compiler: CompilerInterface = CompilerFactory.create(cli.format, {
|
||||||
.execute();
|
indentation: cli.formatIndentation
|
||||||
|
});
|
||||||
|
extract.setCompiler(compiler);
|
||||||
|
|
||||||
|
const parsers: ParserInterface[] = [
|
||||||
|
new PipeParser(),
|
||||||
|
new DirectiveParser(),
|
||||||
|
new ServiceParser()
|
||||||
|
];
|
||||||
|
if (cli.marker) {
|
||||||
|
parsers.push(new FunctionParser({
|
||||||
|
identifier: cli.marker
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
extract.setParsers(parsers);
|
||||||
|
|
||||||
|
extract.execute();
|
||||||
|
@@ -14,6 +14,7 @@ export interface ExtractTaskOptionsInterface {
|
|||||||
sort?: boolean;
|
sort?: boolean;
|
||||||
clean?: boolean;
|
clean?: boolean;
|
||||||
patterns?: string[];
|
patterns?: string[];
|
||||||
|
verbose?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExtractTask implements TaskInterface {
|
export class ExtractTask implements TaskInterface {
|
||||||
@@ -22,7 +23,8 @@ export class ExtractTask implements TaskInterface {
|
|||||||
replace: false,
|
replace: false,
|
||||||
sort: false,
|
sort: false,
|
||||||
clean: false,
|
clean: false,
|
||||||
patterns: []
|
patterns: [],
|
||||||
|
verbose: true
|
||||||
};
|
};
|
||||||
|
|
||||||
protected _parsers: ParserInterface[] = [];
|
protected _parsers: ParserInterface[] = [];
|
||||||
@@ -41,11 +43,6 @@ export class ExtractTask implements TaskInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const collection = this._extract();
|
const collection = this._extract();
|
||||||
if (collection.isEmpty()) {
|
|
||||||
this._out(chalk.yellow('Did not find any extractable strings\n'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._out(chalk.green('Extracted %d strings\n'), collection.count());
|
this._out(chalk.green('Extracted %d strings\n'), collection.count());
|
||||||
this._save(collection);
|
this._save(collection);
|
||||||
}
|
}
|
||||||
@@ -69,7 +66,7 @@ export class ExtractTask implements TaskInterface {
|
|||||||
let collection: TranslationCollection = new TranslationCollection();
|
let collection: TranslationCollection = new TranslationCollection();
|
||||||
this._input.forEach(dir => {
|
this._input.forEach(dir => {
|
||||||
this._readDir(dir, this._options.patterns).forEach(path => {
|
this._readDir(dir, this._options.patterns).forEach(path => {
|
||||||
this._out(chalk.gray('- %s'), path);
|
this._options.verbose && this._out(chalk.gray('- %s'), path);
|
||||||
const contents: string = fs.readFileSync(path, 'utf-8');
|
const contents: string = fs.readFileSync(path, 'utf-8');
|
||||||
this._parsers.forEach((parser: ParserInterface) => {
|
this._parsers.forEach((parser: ParserInterface) => {
|
||||||
collection = collection.union(parser.extract(contents, path));
|
collection = collection.union(parser.extract(contents, path));
|
||||||
@@ -109,7 +106,7 @@ export class ExtractTask implements TaskInterface {
|
|||||||
|
|
||||||
if (this._options.clean) {
|
if (this._options.clean) {
|
||||||
const collectionCount = processedCollection.count();
|
const collectionCount = processedCollection.count();
|
||||||
processedCollection = processedCollection.intersect(processedCollection);
|
processedCollection = processedCollection.intersect(collection);
|
||||||
const removeCount = collectionCount - processedCollection.count();
|
const removeCount = collectionCount - processedCollection.count();
|
||||||
if (removeCount > 0) {
|
if (removeCount > 0) {
|
||||||
this._out(chalk.dim('- removed %d obsolete strings'), removeCount);
|
this._out(chalk.dim('- removed %d obsolete strings'), removeCount);
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import { CompilerInterface } from './compiler.interface';
|
import { CompilerInterface } from './compiler.interface';
|
||||||
import { TranslationCollection } from '../utils/translation.collection';
|
import { TranslationCollection } from '../utils/translation.collection';
|
||||||
|
|
||||||
|
import * as flat from 'flat';
|
||||||
|
|
||||||
export class JsonCompiler implements CompilerInterface {
|
export class JsonCompiler implements CompilerInterface {
|
||||||
|
|
||||||
public indentation: string = '\t';
|
public indentation: string = '\t';
|
||||||
@@ -18,7 +20,15 @@ export class JsonCompiler implements CompilerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public parse(contents: string): TranslationCollection {
|
public parse(contents: string): TranslationCollection {
|
||||||
return new TranslationCollection(JSON.parse(contents));
|
let values: any = JSON.parse(contents);
|
||||||
|
if (this._isNamespacedJsonFormat(values)) {
|
||||||
|
values = flat.flatten(values);
|
||||||
|
}
|
||||||
|
return new TranslationCollection(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _isNamespacedJsonFormat(values: any): boolean {
|
||||||
|
return Object.keys(values).some(key => typeof values[key] === 'object');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
export * from './utils/translation.collection';
|
export * from './utils/translation.collection';
|
||||||
export * from './utils/ast-utils';
|
export * from './utils/utils';
|
||||||
|
|
||||||
export * from './cli/cli';
|
export * from './cli/cli';
|
||||||
export * from './cli/tasks/task.interface';
|
export * from './cli/tasks/task.interface';
|
||||||
@@ -7,9 +7,11 @@ export * from './cli/tasks/extract.task';
|
|||||||
|
|
||||||
export * from './parsers/parser.interface';
|
export * from './parsers/parser.interface';
|
||||||
export * from './parsers/abstract-template.parser';
|
export * from './parsers/abstract-template.parser';
|
||||||
|
export * from './parsers/abstract-ast.parser';
|
||||||
export * from './parsers/directive.parser';
|
export * from './parsers/directive.parser';
|
||||||
export * from './parsers/pipe.parser';
|
export * from './parsers/pipe.parser';
|
||||||
export * from './parsers/service.parser';
|
export * from './parsers/service.parser';
|
||||||
|
export * from './parsers/function.parser';
|
||||||
|
|
||||||
export * from './compilers/compiler.interface';
|
export * from './compilers/compiler.interface';
|
||||||
export * from './compilers/compiler.factory';
|
export * from './compilers/compiler.factory';
|
||||||
|
65
src/parsers/abstract-ast.parser.ts
Normal file
65
src/parsers/abstract-ast.parser.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
|
export abstract class AbstractAstParser {
|
||||||
|
|
||||||
|
protected _sourceFile: ts.SourceFile;
|
||||||
|
|
||||||
|
protected _createSourceFile(path: string, contents: string): ts.SourceFile {
|
||||||
|
return ts.createSourceFile(path, contents, null, /*setParentNodes */ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get strings from function call's first argument
|
||||||
|
*/
|
||||||
|
protected _getCallArgStrings(callNode: ts.CallExpression): string[] {
|
||||||
|
if (!callNode.arguments.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstArg = callNode.arguments[0];
|
||||||
|
switch (firstArg.kind) {
|
||||||
|
case ts.SyntaxKind.StringLiteral:
|
||||||
|
case ts.SyntaxKind.FirstTemplateToken:
|
||||||
|
return [(firstArg as ts.StringLiteral).text];
|
||||||
|
case ts.SyntaxKind.ArrayLiteralExpression:
|
||||||
|
return (firstArg as ts.ArrayLiteralExpression).elements
|
||||||
|
.map((element: ts.StringLiteral) => element.text);
|
||||||
|
case ts.SyntaxKind.Identifier:
|
||||||
|
console.log('WARNING: We cannot extract variable values passed to TranslateService (yet)');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log(`SKIP: Unknown argument type: '${this._syntaxKindToName(firstArg.kind)}'`, firstArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all child nodes of a kind
|
||||||
|
*/
|
||||||
|
protected _findNodes(node: ts.Node, kind: ts.SyntaxKind): ts.Node[] {
|
||||||
|
const childrenNodes: ts.Node[] = node.getChildren(this._sourceFile);
|
||||||
|
const initialValue: ts.Node[] = node.kind === kind ? [node] : [];
|
||||||
|
|
||||||
|
return childrenNodes.reduce((result: ts.Node[], childNode: ts.Node) => {
|
||||||
|
return result.concat(this._findNodes(childNode, kind));
|
||||||
|
}, initialValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _syntaxKindToName(kind: ts.SyntaxKind): string {
|
||||||
|
return ts.SyntaxKind[kind];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _printAllChildren(sourceFile: ts.SourceFile, node: ts.Node, depth = 0): void {
|
||||||
|
console.log(
|
||||||
|
new Array(depth + 1).join('----'),
|
||||||
|
`[${node.kind}]`,
|
||||||
|
this._syntaxKindToName(node.kind),
|
||||||
|
`[pos: ${node.pos}-${node.end}]`,
|
||||||
|
':\t\t\t',
|
||||||
|
node.getFullText(sourceFile).trim()
|
||||||
|
);
|
||||||
|
|
||||||
|
depth++;
|
||||||
|
node.getChildren(sourceFile).forEach(childNode => this._printAllChildren(sourceFile, childNode, depth));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -2,7 +2,9 @@ import { ParserInterface } from './parser.interface';
|
|||||||
import { AbstractTemplateParser } from './abstract-template.parser';
|
import { AbstractTemplateParser } from './abstract-template.parser';
|
||||||
import { TranslationCollection } from '../utils/translation.collection';
|
import { TranslationCollection } from '../utils/translation.collection';
|
||||||
|
|
||||||
import * as $ from 'cheerio';
|
import * as cheerio from 'cheerio';
|
||||||
|
|
||||||
|
const $ = cheerio.load('', {xmlMode: true});
|
||||||
|
|
||||||
export class DirectiveParser extends AbstractTemplateParser implements ParserInterface {
|
export class DirectiveParser extends AbstractTemplateParser implements ParserInterface {
|
||||||
|
|
||||||
|
61
src/parsers/function.parser.ts
Normal file
61
src/parsers/function.parser.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { ParserInterface } from './parser.interface';
|
||||||
|
import { AbstractAstParser } from './abstract-ast.parser';
|
||||||
|
import { TranslationCollection } from '../utils/translation.collection';
|
||||||
|
|
||||||
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
|
export class FunctionParser extends AbstractAstParser implements ParserInterface {
|
||||||
|
|
||||||
|
protected _functionIdentifier: string = '_';
|
||||||
|
|
||||||
|
public constructor(options?: any) {
|
||||||
|
super();
|
||||||
|
if (options && typeof options.identifier !== 'undefined') {
|
||||||
|
this._functionIdentifier = options.identifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public extract(contents: string, path?: string): TranslationCollection {
|
||||||
|
let collection: TranslationCollection = new TranslationCollection();
|
||||||
|
|
||||||
|
this._sourceFile = this._createSourceFile(path, contents);
|
||||||
|
|
||||||
|
const callNodes = this._findCallNodes();
|
||||||
|
callNodes.forEach(callNode => {
|
||||||
|
const keys: string[] = this._getCallArgStrings(callNode);
|
||||||
|
if (keys && keys.length) {
|
||||||
|
collection = collection.addKeys(keys);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all calls to marker function
|
||||||
|
*/
|
||||||
|
protected _findCallNodes(node?: ts.Node): ts.CallExpression[] {
|
||||||
|
if (!node) {
|
||||||
|
node = this._sourceFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
let callNodes = this._findNodes(node, ts.SyntaxKind.CallExpression) as ts.CallExpression[];
|
||||||
|
callNodes = callNodes
|
||||||
|
.filter(callNode => {
|
||||||
|
// Only call expressions with arguments
|
||||||
|
if (callNode.arguments.length < 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const identifier = (callNode.getChildAt(0) as ts.Identifier).text;
|
||||||
|
if (identifier !== this._functionIdentifier) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return callNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -15,10 +15,10 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac
|
|||||||
protected _parseTemplate(template: string): TranslationCollection {
|
protected _parseTemplate(template: string): TranslationCollection {
|
||||||
let collection: TranslationCollection = new TranslationCollection();
|
let collection: TranslationCollection = new TranslationCollection();
|
||||||
|
|
||||||
const regExp: RegExp = /(['"`])([^>\1\r\n]*?)\1\s*\|\s*translate/g;
|
const regExp: RegExp = /(['"`])((?:(?!\1).|\\\1)+)\1\s*\|\s*translate/g;
|
||||||
let matches: RegExpExecArray;
|
let matches: RegExpExecArray;
|
||||||
while (matches = regExp.exec(template)) {
|
while (matches = regExp.exec(template)) {
|
||||||
collection = collection.add(matches[2]);
|
collection = collection.add(matches[2].split('\\\'').join('\''));
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
|
@@ -1,48 +1,46 @@
|
|||||||
import { ParserInterface } from './parser.interface';
|
import { ParserInterface } from './parser.interface';
|
||||||
|
import { AbstractAstParser } from './abstract-ast.parser';
|
||||||
import { TranslationCollection } from '../utils/translation.collection';
|
import { TranslationCollection } from '../utils/translation.collection';
|
||||||
import { syntaxKindToName } from '../utils/ast-utils';
|
|
||||||
|
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
export class ServiceParser implements ParserInterface {
|
export class ServiceParser extends AbstractAstParser implements ParserInterface {
|
||||||
|
|
||||||
protected _sourceFile: ts.SourceFile;
|
protected _sourceFile: ts.SourceFile;
|
||||||
|
|
||||||
protected _instancePropertyName: any;
|
|
||||||
protected _serviceClassName: string = 'TranslateService';
|
|
||||||
protected _serviceMethodNames: string[] = ['get', 'instant'];
|
|
||||||
|
|
||||||
public extract(contents: string, path?: string): TranslationCollection {
|
public extract(contents: string, path?: string): TranslationCollection {
|
||||||
let collection: TranslationCollection = new TranslationCollection();
|
let collection: TranslationCollection = new TranslationCollection();
|
||||||
|
|
||||||
this._sourceFile = this._createSourceFile(path, contents);
|
this._sourceFile = this._createSourceFile(path, contents);
|
||||||
|
const classNodes = this._findClassNodes(this._sourceFile);
|
||||||
this._instancePropertyName = this._getInstancePropertyName();
|
classNodes.forEach(classNode => {
|
||||||
if (!this._instancePropertyName) {
|
const constructorNode = this._findConstructorNode(classNode);
|
||||||
return collection;
|
if (!constructorNode) {
|
||||||
}
|
return;
|
||||||
|
|
||||||
const callNodes = this._findCallNodes();
|
|
||||||
callNodes.forEach(callNode => {
|
|
||||||
const keys: string[] = this._getCallArgStrings(callNode);
|
|
||||||
if (keys && keys.length) {
|
|
||||||
collection = collection.addKeys(keys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const propertyName: string = this._findTranslateServicePropertyName(constructorNode);
|
||||||
|
if (!propertyName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const callNodes = this._findCallNodes(classNode, propertyName);
|
||||||
|
callNodes.forEach(callNode => {
|
||||||
|
const keys: string[] = this._getCallArgStrings(callNode);
|
||||||
|
if (keys && keys.length) {
|
||||||
|
collection = collection.addKeys(keys);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _createSourceFile(path: string, contents: string): ts.SourceFile {
|
|
||||||
return ts.createSourceFile(path, contents, null, /*setParentNodes */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect what the TranslateService instance property
|
* Detect what the TranslateService instance property
|
||||||
* is called by inspecting constructor params
|
* is called by inspecting constructor arguments
|
||||||
*/
|
*/
|
||||||
protected _getInstancePropertyName(): string {
|
protected _findTranslateServicePropertyName(constructorNode: ts.ConstructorDeclaration): string {
|
||||||
const constructorNode = this._findConstructorNode();
|
|
||||||
if (!constructorNode) {
|
if (!constructorNode) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -53,13 +51,18 @@ export class ServiceParser implements ParserInterface {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parameter has no type
|
||||||
|
if (!parameter.type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure className is of the correct type
|
// Make sure className is of the correct type
|
||||||
const parameterType: ts.Identifier = (parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier;
|
const parameterType: ts.Identifier = (parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier;
|
||||||
if (!parameterType) {
|
if (!parameterType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const className: string = parameterType.text;
|
const className: string = parameterType.text;
|
||||||
if (className !== this._serviceClassName) {
|
if (className !== 'TranslateService') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,29 +75,34 @@ export class ServiceParser implements ParserInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find first constructor
|
* Find class nodes
|
||||||
*/
|
*/
|
||||||
protected _findConstructorNode(): ts.ConstructorDeclaration {
|
protected _findClassNodes(node: ts.Node): ts.ClassDeclaration[] {
|
||||||
const constructors = this._findNodes(this._sourceFile, ts.SyntaxKind.Constructor, true) as ts.ConstructorDeclaration[];
|
return this._findNodes(node, ts.SyntaxKind.ClassDeclaration) as ts.ClassDeclaration[];
|
||||||
if (constructors.length) {
|
}
|
||||||
return constructors[0];
|
|
||||||
|
/**
|
||||||
|
* Find constructor
|
||||||
|
*/
|
||||||
|
protected _findConstructorNode(node: ts.ClassDeclaration): ts.ConstructorDeclaration {
|
||||||
|
const constructorNodes = this._findNodes(node, ts.SyntaxKind.Constructor) as ts.ConstructorDeclaration[];
|
||||||
|
if (constructorNodes) {
|
||||||
|
return constructorNodes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all calls to TranslateService methods
|
* Find all calls to TranslateService methods
|
||||||
*/
|
*/
|
||||||
protected _findCallNodes(node?: ts.Node): ts.CallExpression[] {
|
protected _findCallNodes(node: ts.Node, propertyIdentifier: string): ts.CallExpression[] {
|
||||||
if (!node) {
|
|
||||||
node = this._sourceFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
let callNodes = this._findNodes(node, ts.SyntaxKind.CallExpression) as ts.CallExpression[];
|
let callNodes = this._findNodes(node, ts.SyntaxKind.CallExpression) as ts.CallExpression[];
|
||||||
callNodes = callNodes
|
callNodes = callNodes
|
||||||
// Only call expressions with arguments
|
|
||||||
.filter(callNode => callNode.arguments.length > 0)
|
|
||||||
// More filters
|
|
||||||
.filter(callNode => {
|
.filter(callNode => {
|
||||||
|
// Only call expressions with arguments
|
||||||
|
if (callNode.arguments.length < 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const propAccess = callNode.getChildAt(0).getChildAt(0) as ts.PropertyAccessExpression;
|
const propAccess = callNode.getChildAt(0).getChildAt(0) as ts.PropertyAccessExpression;
|
||||||
if (!propAccess || propAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
|
if (!propAccess || propAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
|
||||||
return false;
|
return false;
|
||||||
@@ -102,7 +110,7 @@ export class ServiceParser implements ParserInterface {
|
|||||||
if (!propAccess.getFirstToken() || propAccess.getFirstToken().kind !== ts.SyntaxKind.ThisKeyword) {
|
if (!propAccess.getFirstToken() || propAccess.getFirstToken().kind !== ts.SyntaxKind.ThisKeyword) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (propAccess.name.text !== this._instancePropertyName) {
|
if (propAccess.name.text !== propertyIdentifier) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +118,7 @@ export class ServiceParser implements ParserInterface {
|
|||||||
if (!methodAccess || methodAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
|
if (!methodAccess || methodAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!methodAccess.name || this._serviceMethodNames.indexOf(methodAccess.name.text) === -1) {
|
if (!methodAccess.name || (methodAccess.name.text !== 'get' && methodAccess.name.text !== 'instant' && methodAccess.name.text !== 'stream')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,44 +128,4 @@ export class ServiceParser implements ParserInterface {
|
|||||||
return callNodes;
|
return callNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get strings from function call's first argument
|
|
||||||
*/
|
|
||||||
protected _getCallArgStrings(callNode: ts.CallExpression): string[] {
|
|
||||||
if (!callNode.arguments.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstArg = callNode.arguments[0];
|
|
||||||
switch (firstArg.kind) {
|
|
||||||
case ts.SyntaxKind.StringLiteral:
|
|
||||||
case ts.SyntaxKind.FirstTemplateToken:
|
|
||||||
return [(firstArg as ts.StringLiteral).text];
|
|
||||||
case ts.SyntaxKind.ArrayLiteralExpression:
|
|
||||||
return (firstArg as ts.ArrayLiteralExpression).elements
|
|
||||||
.map((element: ts.StringLiteral) => element.text);
|
|
||||||
case ts.SyntaxKind.Identifier:
|
|
||||||
console.log('WARNING: We cannot extract variable values passed to TranslateService (yet)');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log(`SKIP: Unknown argument type: '${syntaxKindToName(firstArg.kind)}'`, firstArg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find all child nodes of a kind
|
|
||||||
*/
|
|
||||||
protected _findNodes(node: ts.Node, kind: ts.SyntaxKind, onlyOne: boolean = false): ts.Node[] {
|
|
||||||
if (node.kind === kind && onlyOne) {
|
|
||||||
return [node];
|
|
||||||
}
|
|
||||||
|
|
||||||
const childrenNodes: ts.Node[] = node.getChildren(this._sourceFile);
|
|
||||||
const initialValue: ts.Node[] = node.kind === kind ? [node] : [];
|
|
||||||
|
|
||||||
return childrenNodes.reduce((result: ts.Node[], childNode: ts.Node) => {
|
|
||||||
return result.concat(this._findNodes(childNode, kind));
|
|
||||||
}, initialValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +0,0 @@
|
|||||||
import * as ts from 'typescript';
|
|
||||||
|
|
||||||
export function printAllChildren(sourceFile: ts.SourceFile, node: ts.Node, depth = 0) {
|
|
||||||
console.log(
|
|
||||||
new Array(depth + 1).join('----'),
|
|
||||||
`[${node.kind}]`,
|
|
||||||
syntaxKindToName(node.kind),
|
|
||||||
`[pos: ${node.pos}-${node.end}]`,
|
|
||||||
':\t\t\t',
|
|
||||||
node.getFullText(sourceFile).trim()
|
|
||||||
);
|
|
||||||
|
|
||||||
depth++;
|
|
||||||
node.getChildren(sourceFile).forEach(childNode => printAllChildren(sourceFile, childNode, depth));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function syntaxKindToName(kind: ts.SyntaxKind) {
|
|
||||||
return ts.SyntaxKind[kind];
|
|
||||||
}
|
|
@@ -1,6 +1,6 @@
|
|||||||
export interface TranslationType {
|
export interface TranslationType {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
};
|
}
|
||||||
|
|
||||||
export class TranslationCollection {
|
export class TranslationCollection {
|
||||||
|
|
||||||
|
3
src/utils/utils.ts
Normal file
3
src/utils/utils.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function _(key: string | string[]): string | string[] {
|
||||||
|
return key;
|
||||||
|
}
|
@@ -118,4 +118,10 @@ describe('DirectiveParser', () => {
|
|||||||
expect(template).to.equal('<p translate="KEY">Hello World</p>');
|
expect(template).to.equal('<p translate="KEY">Hello World</p>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should extract contents from within custom tags', () => {
|
||||||
|
const contents = `<custom-table><tbody><tr><td translate>Hello World</td></tr></tbody></custom-table>`;
|
||||||
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['Hello World']);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
27
tests/parsers/function.parser.spec.ts
Normal file
27
tests/parsers/function.parser.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
import { FunctionParser } from '../../src/parsers/function.parser';
|
||||||
|
|
||||||
|
describe('FunctionParser', () => {
|
||||||
|
|
||||||
|
const componentFilename: string = 'test.component.ts';
|
||||||
|
|
||||||
|
let parser: FunctionParser;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
parser = new FunctionParser();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should extract strings using marker function', () => {
|
||||||
|
const contents = `
|
||||||
|
import { _ } from '@biesbjerg/ngx-translate-extract';
|
||||||
|
_('Hello world');
|
||||||
|
_(['I', 'am', 'extracted']);
|
||||||
|
otherFunction('But I am not');
|
||||||
|
`;
|
||||||
|
const keys = parser.extract(contents, componentFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['Hello world', 'I', 'am', 'extracted']);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -18,6 +18,12 @@ describe('PipeParser', () => {
|
|||||||
expect(keys).to.deep.equal(['SomeKey_NotWorking']);
|
expect(keys).to.deep.equal(['SomeKey_NotWorking']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should extract string using pipe, but between quotes only', () => {
|
||||||
|
const contents = `<input class="form-control" type="text" placeholder="{{'user.settings.form.phone.placeholder' | translate}}" [formControl]="settingsForm.controls['phone']">`;
|
||||||
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['user.settings.form.phone.placeholder']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should extract interpolated strings using translate pipe', () => {
|
it('should extract interpolated strings using translate pipe', () => {
|
||||||
const contents = `Hello {{ 'World' | translate }}`;
|
const contents = `Hello {{ 'World' | translate }}`;
|
||||||
const keys = parser.extract(contents, templateFilename).keys();
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
@@ -25,11 +31,17 @@ describe('PipeParser', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extract strings with escaped quotes', () => {
|
it('should extract strings with escaped quotes', () => {
|
||||||
const contents = `Hello {{ 'World\'s largest potato' | translate }}`;
|
const contents = `Hello {{ 'World\\'s largest potato' | translate }}`;
|
||||||
const keys = parser.extract(contents, templateFilename).keys();
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
expect(keys).to.deep.equal([`World's largest potato`]);
|
expect(keys).to.deep.equal([`World's largest potato`]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should extract strings with multiple escaped quotes', () => {
|
||||||
|
const contents = `{{ 'C\\'est ok. C\\'est ok' | translate }}`;
|
||||||
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
|
expect(keys).to.deep.equal([`C'est ok. C'est ok`]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should extract interpolated strings using translate pipe in attributes', () => {
|
it('should extract interpolated strings using translate pipe in attributes', () => {
|
||||||
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
|
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
|
||||||
const keys = parser.extract(contents, templateFilename).keys();
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
|
@@ -60,6 +60,19 @@ describe('ServiceParser', () => {
|
|||||||
expect(keys).to.deep.equal(['Hello World']);
|
expect(keys).to.deep.equal(['Hello World']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should extract strings in TranslateService\'s stream() method', () => {
|
||||||
|
const contents = `
|
||||||
|
@Component({ })
|
||||||
|
export class AppComponent {
|
||||||
|
public constructor(protected _translateService: TranslateService) { }
|
||||||
|
public test() {
|
||||||
|
this._translateService.stream('Hello World');
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const keys = parser.extract(contents, componentFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['Hello World']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should extract array of strings in TranslateService\'s get() method', () => {
|
it('should extract array of strings in TranslateService\'s get() method', () => {
|
||||||
const contents = `
|
const contents = `
|
||||||
@Component({ })
|
@Component({ })
|
||||||
@@ -86,7 +99,20 @@ describe('ServiceParser', () => {
|
|||||||
expect(key).to.deep.equal(['Hello', 'World']);
|
expect(key).to.deep.equal(['Hello', 'World']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not extract strings in get()/instant() methods of other services', () => {
|
it('should extract array of strings in TranslateService\'s stream() method', () => {
|
||||||
|
const contents = `
|
||||||
|
@Component({ })
|
||||||
|
export class AppComponent {
|
||||||
|
public constructor(protected _translateService: TranslateService) { }
|
||||||
|
public test() {
|
||||||
|
this._translateService.stream(['Hello', 'World']);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const key = parser.extract(contents, componentFilename).keys();
|
||||||
|
expect(key).to.deep.equal(['Hello', 'World']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not extract strings in get()/instant()/stream() methods of other services', () => {
|
||||||
const contents = `
|
const contents = `
|
||||||
@Component({ })
|
@Component({ })
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
@@ -97,6 +123,7 @@ describe('ServiceParser', () => {
|
|||||||
public test() {
|
public test() {
|
||||||
this._otherService.get('Hello World');
|
this._otherService.get('Hello World');
|
||||||
this._otherService.instant('Hi there');
|
this._otherService.instant('Hi there');
|
||||||
|
this._otherService.stream('Hi there');
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const keys = parser.extract(contents, componentFilename).keys();
|
const keys = parser.extract(contents, componentFilename).keys();
|
||||||
@@ -151,4 +178,51 @@ describe('ServiceParser', () => {
|
|||||||
expect(keys).to.deep.equal(['You are expected at {{time}}']);
|
expect(keys).to.deep.equal(['You are expected at {{time}}']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not crash when constructor parameter has no type', () => {
|
||||||
|
const contents = `
|
||||||
|
@Component({ })
|
||||||
|
export class AppComponent {
|
||||||
|
public constructor(protected _translateService) { }
|
||||||
|
public test() {
|
||||||
|
this._translateService.instant('Hello World');
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const keys = parser.extract(contents, componentFilename).keys();
|
||||||
|
expect(keys).to.deep.equal([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should extract strings from all classes in the file', () => {
|
||||||
|
const contents = `
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
export class Stuff {
|
||||||
|
thing: string;
|
||||||
|
translate: any;
|
||||||
|
constructor(thing: string) {
|
||||||
|
this.translate.get('Not me');
|
||||||
|
this.thing = thing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Injectable()
|
||||||
|
export class MyComponent {
|
||||||
|
constructor(public translate: TranslateService) {
|
||||||
|
this.translate.instant("Extract me!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class OtherClass {
|
||||||
|
constructor(thing: string, _translate: TranslateService) {
|
||||||
|
this._translate.get("Do not extract me");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Injectable()
|
||||||
|
export class AuthService {
|
||||||
|
constructor(public translate: TranslateService) {
|
||||||
|
this.translate.instant("Hello!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const keys = parser.extract(contents, componentFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['Extract me!', 'Hello!']);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user