Skip to content

Commit

Permalink
feat(@formatjs/cli): add more debugging info to extraction, fix #2044
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Aug 30, 2020
1 parent 7fe75fe commit 20b832e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages/intl-getcanonicallocales/src/data/
packages/intl-messageformat-parser/src/parser.ts
packages/intl-numberformat/src/data/
packages/ecma402-abstract/src/NumberFormat/digit-mapping.json
packages/cli/tests/extract/typescript/err.tsx
test262*
test262/
website/.docusaurus
Expand Down
18 changes: 17 additions & 1 deletion packages/cli/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,33 @@ function processFile(
};
}

ts.transpileModule(source, {
const output = ts.transpileModule(source, {
compilerOptions: {
allowJs: true,
target: ts.ScriptTarget.ESNext,
noEmit: true,
experimentalDecorators: true,
},
reportDiagnostics: true,
fileName: fn,
transformers: {
before: [transform(opts)],
},
});
if (output.diagnostics) {
const errs = output.diagnostics.filter(
d => d.category === ts.DiagnosticCategory.Error
);
if (errs.length) {
throw new Error(
ts.formatDiagnosticsWithColorAndContext(errs, {
getCanonicalFileName: fileName => fileName,
getCurrentDirectory: () => process.cwd(),
getNewLine: () => ts.sys.newLine,
})
);
}
}
return {messages, meta};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/cli/tests/extract/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,11 @@ test('duplicated descriptor ids throws', async () => {
);
}).rejects.toThrowError('Duplicate message id: "foo"');
}, 20000);

test('invalid syntax should throw', async () => {
expect(async () => {
await exec(
`${BIN_PATH} extract --throws '${join(__dirname, 'typescript/err.tsx')}'`
);
}).rejects.toThrowError('TS1005');
}, 20000);
1 change: 1 addition & 0 deletions packages/cli/tests/extract/typescript/err.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import from 'foo'

0 comments on commit 20b832e

Please sign in to comment.