@formatjs/ts-transformer 3.9.10 → 3.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/index.d.ts +4 -0
  2. package/index.d.ts.map +1 -0
  3. package/index.js +6 -0
  4. package/package.json +2 -2
  5. package/src/console_utils.d.ts +4 -0
  6. package/src/console_utils.d.ts.map +1 -0
  7. package/src/console_utils.js +31 -0
  8. package/src/interpolate-name.d.ts +15 -0
  9. package/src/interpolate-name.d.ts.map +1 -0
  10. package/src/interpolate-name.js +90 -0
  11. package/src/transform.d.ts +78 -0
  12. package/src/transform.d.ts.map +1 -0
  13. package/src/transform.js +479 -0
  14. package/src/types.d.ts +12 -0
  15. package/src/types.d.ts.map +1 -0
  16. package/src/types.js +2 -0
  17. package/ts-jest-integration.d.ts +6 -0
  18. package/ts-jest-integration.d.ts.map +1 -0
  19. package/ts-jest-integration.js +10 -0
  20. package/BUILD +0 -82
  21. package/CHANGELOG.md +0 -713
  22. package/examples/compile.ts +0 -50
  23. package/index.ts +0 -3
  24. package/integration-tests/BUILD +0 -37
  25. package/integration-tests/integration/comp.tsx +0 -40
  26. package/integration-tests/integration/jest.config.js +0 -25
  27. package/integration-tests/integration/ts-jest.test.tsx +0 -32
  28. package/integration-tests/package.json +0 -5
  29. package/integration-tests/vue/fixtures/index.vue +0 -30
  30. package/integration-tests/vue/fixtures/main.ts +0 -4
  31. package/integration-tests/vue/integration.test.ts +0 -75
  32. package/src/console_utils.ts +0 -32
  33. package/src/interpolate-name.ts +0 -147
  34. package/src/transform.ts +0 -764
  35. package/src/types.ts +0 -12
  36. package/tests/__snapshots__/index.test.ts.snap +0 -908
  37. package/tests/fixtures/FormattedMessage.tsx +0 -35
  38. package/tests/fixtures/additionalComponentNames.tsx +0 -16
  39. package/tests/fixtures/additionalFunctionNames.tsx +0 -20
  40. package/tests/fixtures/ast.tsx +0 -83
  41. package/tests/fixtures/defineMessages.tsx +0 -67
  42. package/tests/fixtures/defineMessagesPreserveWhitespace.tsx +0 -87
  43. package/tests/fixtures/descriptionsAsObjects.tsx +0 -17
  44. package/tests/fixtures/extractFromFormatMessage.tsx +0 -45
  45. package/tests/fixtures/extractFromFormatMessageStateless.tsx +0 -46
  46. package/tests/fixtures/extractSourceLocation.tsx +0 -8
  47. package/tests/fixtures/formatMessageCall.tsx +0 -44
  48. package/tests/fixtures/inline.tsx +0 -26
  49. package/tests/fixtures/nested.tsx +0 -10
  50. package/tests/fixtures/noImport.tsx +0 -52
  51. package/tests/fixtures/overrideIdFn.tsx +0 -70
  52. package/tests/fixtures/removeDefaultMessage.tsx +0 -22
  53. package/tests/fixtures/removeDescription.tsx +0 -22
  54. package/tests/fixtures/resourcePath.tsx +0 -23
  55. package/tests/fixtures/stringConcat.tsx +0 -26
  56. package/tests/fixtures/templateLiteral.tsx +0 -21
  57. package/tests/index.test.ts +0 -127
  58. package/tests/interpolate-name.test.ts +0 -14
  59. package/ts-jest-integration.ts +0 -9
  60. package/tsconfig.json +0 -5
@@ -1,23 +0,0 @@
1
- export function foo() {
2
- props.intl.formatMessage(
3
- {
4
- defaultMessage: 'props {intl}',
5
- description: 'bar',
6
- },
7
- {bar: 'bar'}
8
- )
9
- this.props.intl.formatMessage(
10
- {
11
- defaultMessage: 'this props {intl}',
12
- description: 'bar',
13
- },
14
- {bar: 'bar'}
15
- )
16
- return intl.formatMessage(
17
- {
18
- defaultMessage: 'foo {bar}',
19
- description: 'bar',
20
- },
21
- {bar: 'bar'}
22
- )
23
- }
@@ -1,26 +0,0 @@
1
- import React, {Component} from 'react'
2
- import {FormattedMessage, defineMessage} from 'react-intl'
3
-
4
- export default class Foo extends Component {
5
- render() {
6
- return (
7
- <div>
8
- <FormattedMessage
9
- id={'foo.bar.baz' + 'id'}
10
- defaultMessage={'Hello World!' + 'far' + 'baz'}
11
- description="The default message."
12
- />
13
- {intl.formatMessage({
14
- id: 'header',
15
- defaultMessage: 'Hello World!' + 'foo' + 'bar',
16
- description: 'The default message',
17
- })}
18
- {defineMessage({
19
- id: 'header2',
20
- defaultMessage: 'Hello World!',
21
- description: 'The default message' + ' asd',
22
- })}
23
- </div>
24
- )
25
- }
26
- }
@@ -1,21 +0,0 @@
1
- import React, {Component} from 'react'
2
- import {FormattedMessage, defineMessage} from 'react-intl'
3
-
4
- defineMessage({
5
- id: `template`,
6
- defaultMessage: `should remove
7
- newline and
8
- extra spaces`,
9
- })
10
-
11
- export default class Foo extends Component {
12
- render() {
13
- return (
14
- <FormattedMessage
15
- id="foo.bar.baz"
16
- defaultMessage={`Hello World!`}
17
- description="The default message."
18
- />
19
- )
20
- }
21
- }
@@ -1,127 +0,0 @@
1
- import {join} from 'path'
2
- import {transform, Opts, MessageDescriptor} from '../'
3
- import * as ts from 'typescript'
4
- import {readFile as readFileAsync} from 'fs'
5
- import {promisify} from 'util'
6
-
7
- const readFile = promisify(readFileAsync)
8
-
9
- const FILES_TO_TESTS: Record<string, Partial<Opts>> = {
10
- additionalComponentNames: {
11
- additionalComponentNames: ['CustomMessage'],
12
- pragma: 'react-intl',
13
- },
14
- additionalFunctionNames: {
15
- additionalFunctionNames: ['$formatMessage'],
16
- pragma: 'react-intl',
17
- },
18
- defineMessages: {
19
- pragma: 'react-intl',
20
- },
21
- extractFromFormatMessage: {
22
- pragma: 'react-intl',
23
- },
24
- extractFromFormatMessageStateless: {},
25
- nested: {
26
- overrideIdFn: (id, defaultMessage, description) => {
27
- return `HELLO.${id}.${defaultMessage!.length}.${typeof description}`
28
- },
29
- },
30
- extractSourceLocation: {
31
- extractSourceLocation: true,
32
- },
33
- descriptionsAsObjects: {},
34
- formatMessageCall: {},
35
- FormattedMessage: {},
36
- inline: {},
37
- stringConcat: {},
38
- templateLiteral: {},
39
- overrideIdFn: {
40
- overrideIdFn: (id, defaultMessage, description) => {
41
- return `HELLO.${id}.${defaultMessage!.length}.${typeof description}`
42
- },
43
- },
44
- ast: {
45
- ast: true,
46
- overrideIdFn: (id, defaultMessage, description) => {
47
- return `HELLO.${id}.${defaultMessage!.length}.${typeof description}`
48
- },
49
- },
50
- removeDefaultMessage: {
51
- removeDefaultMessage: true,
52
- },
53
- noImport: {
54
- overrideIdFn: '[hash:base64:5]',
55
- },
56
- resourcePath: {
57
- overrideIdFn: '[name]-[hash:base64:5]',
58
- },
59
- removeDescription: {},
60
- defineMessagesPreserveWhitespace: {
61
- pragma: 'react-intl',
62
- preserveWhitespace: true,
63
- },
64
- }
65
-
66
- const FIXTURES_DIR = join(__dirname, 'fixtures')
67
-
68
- describe('emit asserts for', function () {
69
- const filenames = Object.keys(FILES_TO_TESTS)
70
- filenames.forEach(function (fn) {
71
- if (fn === 'extractSourceLocation') {
72
- it(`[special] ${fn}`, async function () {
73
- const output = await compile(
74
- join(FIXTURES_DIR, `${fn}.tsx`),
75
- FILES_TO_TESTS[fn]
76
- )
77
- // Check code output
78
- expect(output.code).toMatchSnapshot()
79
- expect(output.msgs).toHaveLength(1)
80
- expect(output.msgs[0]).toMatchSnapshot({
81
- file: expect.stringContaining('extractSourceLocation.tsx'),
82
- })
83
- })
84
- } else {
85
- it(fn, async function () {
86
- const output = await compile(
87
- join(FIXTURES_DIR, `${fn}.tsx`),
88
- FILES_TO_TESTS[fn]
89
- )
90
- expect(output).toMatchSnapshot()
91
- })
92
- }
93
- })
94
- })
95
-
96
- async function compile(filePath: string, options?: Partial<Opts>) {
97
- let msgs: MessageDescriptor[] = []
98
- let meta: Record<string, string> = {}
99
- const input = await readFile(filePath, 'utf8')
100
- const output = ts.transpileModule(input, {
101
- compilerOptions: {
102
- target: ts.ScriptTarget.ESNext,
103
- allowJs: true,
104
- },
105
- fileName: filePath,
106
- reportDiagnostics: true,
107
- transformers: {
108
- before: [
109
- transform({
110
- overrideIdFn: '[hash:base64:10]',
111
- onMsgExtracted: (_, extractedMsgs) => {
112
- msgs = msgs.concat(extractedMsgs)
113
- },
114
- onMetaExtracted: (_, m) => {
115
- meta = m
116
- },
117
- ...(options || {}),
118
- }),
119
- ],
120
- },
121
- })
122
- return {
123
- msgs,
124
- meta,
125
- code: output.outputText,
126
- }
127
- }
@@ -1,14 +0,0 @@
1
- import {interpolateName} from '../src/interpolate-name'
2
- import {createHash} from 'crypto'
3
- describe('interpolateName', function () {
4
- it('should match native', function () {
5
- const hasher = createHash('sha1')
6
- const content = 'foo#bar'
7
- hasher.update(content)
8
- expect(
9
- interpolateName({}, '[sha1:contenthash:base64:6]', {
10
- content,
11
- })
12
- ).toBe(hasher.digest('base64').slice(0, 6))
13
- })
14
- })
@@ -1,9 +0,0 @@
1
- import {transformWithTs, Opts} from '.'
2
- import type {TsCompilerInstance} from 'ts-jest'
3
-
4
- export const name = '@formatjs/ts-transformer'
5
- export const version = '2.10.1'
6
-
7
- export function factory(compilerInstance: TsCompilerInstance, opts: Opts) {
8
- return transformWithTs(compilerInstance.configSet.compilerModule, opts)
9
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- // @generated
2
- {
3
- // This is purely for IDE, not for compilation
4
- "extends": "../../tsconfig.json"
5
- }