Skip to content

Commit

Permalink
Fix cli push angular decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
pablotransifex committed Jan 11, 2022
1 parent 472692d commit 3b9aba5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
57 changes: 30 additions & 27 deletions packages/cli/src/api/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,40 +414,43 @@ function extractPhrases(file, relativeFile, options = {}) {
});
},

// Decorator
// Supported SDK Decorators
Decorator({ node }) {
const elem = node.expression;

if (!elem || !elem.arguments || !elem.arguments.length) return;
if (!node.expression.callee.name === 'T') return;

let string = '';
let key = '';
const params = {};
_.each(node.expression.arguments, (arg) => {
if (arg.type === 'StringLiteral') {
string = arg.value;
} else if (arg.type === 'ObjectExpression') {
_.each(arg.properties, (prop) => {
if (prop.key.name === '_key') {
key = prop.value.value;
} else {
params[prop.key.name] = prop.value.value;
}
});
}
});
// Angular SDK T Decorator
if (node && node.expression && node.expression.callee
&& node.expression.callee.name === 'T') {
let string = '';
let key = '';
const params = {};
_.each(node.expression.arguments, (arg) => {
if (arg.type === 'StringLiteral') {
string = arg.value;
} else if (arg.type === 'ObjectExpression') {
_.each(arg.properties, (prop) => {
if (prop.key.name === '_key') {
key = prop.value.value;
} else {
params[prop.key.name] = prop.value.value;
}
});
}
});

if (string) {
const partial = createPayload(string, params, relativeFile, options);
if (!isPayloadValid(partial, options)) return;
if (string) {
const partial = createPayload(string, params, relativeFile, options);
if (!isPayloadValid(partial, options)) return;

mergePayload(HASHES, {
[key || partial.key]: {
string: partial.string,
meta: partial.meta,
},
});
mergePayload(HASHES, {
[key || partial.key]: {
string: partial.string,
meta: partial.meta,
},
});
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/api/extract.hashedkeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('extractPhrases with hashed keys', () => {
});
});

it('works with typescript', async () => {
it('works with angular typescript', async () => {
expect(await extractPhrases('test/fixtures/typescript.ts', 'typescript.ts', {
useHashedKeys: true,
}))
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/api/extract.sourcekeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('extractPhrases with source keys', () => {
});
});

it('works with typescript', async () => {
it('works with angular typescript', async () => {
expect(await extractPhrases('test/fixtures/typescript.ts', 'typescript.ts'))
.to.deep.equal({
'text.monday': {
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/test/fixtures/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class ItemRegistry {
@T('Monday', { _key: 'text.monday' })
weekday: string;

@ViewChild('someInput', { static: true })
someInputRef: ElementRef<any>;

constructor(name: string, id: number) {
this.name = name;
this.id = id;
Expand Down

0 comments on commit 3b9aba5

Please sign in to comment.