Skip to content

Commit

Permalink
chore: editorconfig, refactoring and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Christer Olsen committed Jan 20, 2023
1 parent 86bef2e commit a32b817
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 54 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v8.0.5 (2023-01-19)

- Merged [P4's](https://github.com/P4) PRs ([#1](https://github.com/vendure-ecommerce/ngx-translate-extract/pull/1), [#2](https://github.com/vendure-ecommerce/ngx-translate-extract/pull/2)) in order to improve the pipe parser when it comes to pipe args and structural directives

## v8.0.5 (2023-01-19)

- Fixed some botched imports

## v8.0.4 (2023-01-19)

- First package published under the @colsen1991 namespace
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ For instance, `gettext-parser:1.2.2` does not support HTML tags in translation k
- Original library, idea and code: [Kim Biesbjerg](https://github.com/biesbjerg/ngx-translate-extract) ❤️
- Further updates and improvements were then made by [bartholomej](https://github.com/bartholomej) ❤️
- Further updates and improvements were then made by [michaelbromley](https://github.com/michaelbromley)/[vendure-ecommerce](https://github.com/vendure-ecommerce) ❤️
- Further updates and improvements were made by [P4's](https://github.com/P4) ❤️
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@colsen1991/ngx-translate-extract",
"version": "8.0.5",
"version": "8.0.6",
"description": "Extract strings from projects using ngx-translate",
"author": "Kim Biesbjerg <kim@biesbjerg.com>",
"maintainers": [
Expand All @@ -18,7 +18,6 @@
"dependencies": {
"@angular/compiler": "^13.1.2",
"@phenomnomnominal/tsquery": "^4.1.1",
"@types/expect": "^24.3.0",
"boxen": "^6.2.1",
"colorette": "^2.0.16",
"flat": "^5.0.2",
Expand Down
10 changes: 0 additions & 10 deletions src/parsers/pipe.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ export class PipeParser implements ParserInterface {
return [].concat(...array);
}

protected expressionIsOrHasBindingPipe(exp: any): exp is BindingPipe {
if (exp.name && TRANSLATE_PIPE_NAMES.includes(exp.name)) {
return true;
}
if (exp.exp && exp.exp instanceof BindingPipe) {
return this.expressionIsOrHasBindingPipe(exp.exp);
}
return false;
}

protected parseTemplate(template: string, path: string): TmplAstNode[] {
return parseTemplate(template, path).nodes;
}
Expand Down
75 changes: 33 additions & 42 deletions tests/parsers/pipe.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,50 +210,41 @@ describe('PipeParser', () => {
expect(keys).to.deep.equal([]);
});

it('should extract translate pipe used as pipe argument', () => {
const contents = `{{ value | valueToTranslationKey: ('argument' | translate) }}`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['argument']);
});

it('should extract nested uses of translate pipe', () => {
const contents = `{{ 'Hello' | translate: {world: ('World' | translate)} }}`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});

it('should extract strings from piped arguments inside a function calls on templates', () => {
const contents = `{{ callMe('Hello' | translate, 'World' | translate ) }}`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`Hello`, `World`]);
});
});
});
it('should extract translate pipe used as pipe argument', () => {
const contents = '{{ value | valueToTranslationKey: (\'argument\' | translate) }}';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['argument']);
});

it('should extract from objects in property bindings', () => {
const contents = `
<hello [values]="{
hello: ('Hello' | translate),
world: ('World' | translate) }"></hello>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`Hello`, `World`]);
});
it('should extract nested uses of translate pipe', () => {
const contents = '{{ \'Hello\' | translate: {world: (\'World\' | translate)} }}';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});

it('should extract from structural directives', () => {
const contents = `
<ng-container *ngIf="'Hello' | translate as hello">{{hello}}</ng-container>
`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`Hello`]);
});
it('should extract strings from piped arguments inside a function calls on templates', () => {
const contents = '{{ callMe(\'Hello\' | translate, \'World\' | translate ) }}';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});

it('should extract from objects in property bindings', () => {
const contents = '<hello [values] ="{ hello: (\'Hello\' | translate), world: (\'World\' | translate) }"></hello>';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});

it('should extract from structural directives', () => {
const contents = '<ng-container *ngIf="\'Hello\' | translate as hello">{{hello}}</ng-container>';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello']);
});

it('should extract form inputs to structural directives', () => {
const contents = `
<ng-container *ngTemplateOutlet="template ; context:{
hello: 'Hello' | translate,
world: 'World' | translate,
}"></ng-container>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`Hello`, `World`]);
it('should extract form inputs to structural directives', () => {
const contents = '<ng-container *ngTemplateOutlet="template; context:{ hello: \'Hello\' | translate, world: \'World\' | translate }"></ng-container>';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});
});
});
});

0 comments on commit a32b817

Please sign in to comment.