Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cli push angular decorator #108

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions packages/cli/src/api/parsers/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,43 @@ function babelExtractPhrases(HASHES, source, 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