Skip to content

Commit 61b536b

Browse files
authored
feat: upgrade formatjs dev (#1357)
1 parent 2f5267d commit 61b536b

File tree

7 files changed

+307
-151
lines changed

7 files changed

+307
-151
lines changed

package-lock.json

+275-117
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,28 @@
3636
"react": "global:React"
3737
},
3838
"dependencies": {
39-
"@formatjs/intl-relativetimeformat": "^2.3.1",
39+
"@formatjs/intl-relativetimeformat": "^2.3.3",
4040
"@types/hoist-non-react-statics": "^3.3.1",
4141
"@types/invariant": "^2.2.30",
42-
"@types/react": "^16.8.20",
42+
"@types/react": "^16.8.23",
4343
"hoist-non-react-statics": "^3.3.0",
44-
"intl-format-cache": "^3.3.1",
45-
"intl-locales-supported": "^1.3.1",
46-
"intl-messageformat": "^4.3.0",
44+
"intl-format-cache": "^4.0.0",
45+
"intl-locales-supported": "^1.3.3",
46+
"intl-messageformat-parser": "^2.0.0",
47+
"intl-messageformat": "^5.0.0",
4748
"invariant": "^2.1.1",
4849
"react": "^16.3.0",
4950
"shallow-equal": "^1.1.0"
5051
},
5152
"devDependencies": {
52-
"@babel/cli": "^7.1.2",
53-
"@babel/core": "^7.1.2",
54-
"@babel/node": "^7.0.0",
55-
"@babel/plugin-proposal-class-properties": "^7.1.0",
56-
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
57-
"@babel/plugin-transform-async-to-generator": "^7.1.0",
58-
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
59-
"@babel/preset-env": "^7.1.0",
53+
"@babel/cli": "^7.5.0",
54+
"@babel/core": "^7.5.0",
55+
"@babel/node": "^7.5.0",
56+
"@babel/plugin-proposal-class-properties": "^7.5.0",
57+
"@babel/plugin-proposal-object-rest-spread": "^7.5.2",
58+
"@babel/plugin-transform-async-to-generator": "^7.5.0",
59+
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
60+
"@babel/preset-env": "^7.5.2",
6061
"@babel/preset-react": "^7.0.0",
6162
"@types/benchmark": "^1.0.31",
6263
"@types/enzyme": "^3.10.1",
@@ -66,13 +67,13 @@
6667
"@typescript-eslint/eslint-plugin": "^1.10.2",
6768
"@typescript-eslint/parser": "^1.10.2",
6869
"babel-jest": "^24.8.0",
69-
"babel-plugin-react-intl": "^3.5.0",
70+
"babel-plugin-react-intl": "^4.0.0",
7071
"babel-plugin-transform-member-expression-literals": "^6.9.4",
7172
"babel-plugin-transform-property-literals": "^6.9.4",
7273
"babel-plugin-transform-react-remove-prop-types": "^0.4.18",
7374
"babelify": "^10.0.0",
7475
"benchmark": "^2.1.0",
75-
"browserify": "^16.2.3",
76+
"browserify": "^16.3.0",
7677
"browserify-shim": "^3.8.11",
7778
"cross-env": "^5.2.0",
7879
"enzyme": "^3.6.0",
@@ -84,7 +85,6 @@
8485
"full-icu": "^1.3.0",
8586
"glob": "^7.0.0",
8687
"intl": "^1.2.1",
87-
"intl-messageformat-parser": "^1.8.0",
8888
"intl-pluralrules": "^1.0.3",
8989
"jest": "^24.8.0",
9090
"markdown-toc": "^1.2.0",
@@ -96,7 +96,7 @@
9696
"prop-types": "^15.7.2",
9797
"react-dom": "^16.8.6",
9898
"rimraf": "^2.4.2",
99-
"rollup": "^1.16.4",
99+
"rollup": "^1.16.6",
100100
"rollup-plugin-commonjs": "^10.0.1",
101101
"rollup-plugin-node-resolve": "^5.2.0",
102102
"rollup-plugin-replace": "^2.0.0",

src/format.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
IntlRelativeTimeFormatOptions,
2828
FormattableUnit,
2929
} from '@formatjs/intl-relativetimeformat';
30-
import {MessageTextElement} from 'intl-messageformat-parser';
30+
import {LiteralElement, TYPE} from 'intl-messageformat-parser';
3131

3232
const DATE_TIME_FORMAT_OPTIONS: Array<keyof Intl.DateTimeFormatOptions> = [
3333
'localeMatcher',
@@ -282,11 +282,10 @@ export function formatMessage(
282282
return escapeUnformattedMessage(val);
283283
}
284284
invariant(
285-
val.elements.length === 1 &&
286-
val.elements[0].type === 'messageTextElement',
285+
val.length === 1 && val[0].type === TYPE.literal,
287286
'Message has placeholders but no values was provided'
288287
);
289-
return (val.elements[0] as MessageTextElement).value;
288+
return (val[0] as LiteralElement).value;
290289
}
291290

292291
let formattedMessage;

src/types.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
* Copyrights licensed under the New BSD License.
44
* See the accompanying LICENSE file for terms.
55
*/
6-
import {Formats} from 'intl-messageformat/lib/compiler';
7-
import IntlMessageFormat from 'intl-messageformat';
6+
import IntlMessageFormat, {Formats} from 'intl-messageformat';
87
import IntlRelativeTimeFormat, {
98
IntlRelativeTimeFormatOptions,
109
FormattableUnit,
1110
} from '@formatjs/intl-relativetimeformat';
12-
import {MessageFormatPattern} from 'intl-messageformat-parser';
11+
import {MessageFormatElement} from 'intl-messageformat-parser';
1312

1413
export interface IntlConfig {
1514
locale: string;
1615
timeZone?: string;
1716
formats: CustomFormats;
1817
textComponent: React.ComponentType | keyof React.ReactHTML;
19-
messages: Record<string, string> | Record<string, MessageFormatPattern>;
18+
messages: Record<string, string> | Record<string, MessageFormatElement[]>;
2019
defaultLocale: string;
2120
defaultFormats: CustomFormats;
2221
onError(err: string): void;

test/perf/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
FormattedMessage,
99
// FormattedRelativeTime,
1010
} from '../../dist';
11-
import parser, {MessageFormatPattern} from 'intl-messageformat-parser';
11+
import {parse, MessageFormatElement} from 'intl-messageformat-parser';
1212

1313
const suite = new Suite('renderToString', {
1414
onCycle: function(e: any) {
@@ -97,10 +97,10 @@ suite.add('100 x <FormattedMessage> with placeholder', function() {
9797
);
9898
});
9999

100-
let messageAsts: Record<number, MessageFormatPattern> = {};
100+
let messageAsts: Record<number, MessageFormatElement[]> = {};
101101
for (let i = 0, len = 100; i < len; i += 1) {
102102
const varName = `var${i}`;
103-
messageAsts[i] = parser.parse(
103+
messageAsts[i] = parse(
104104
`{${varName}, plural,
105105
zero {{${varName}, number} message}
106106
one {{${varName}, number} message}
@@ -151,7 +151,7 @@ suite.add('100 x <FormattedMessage> with placeholder, cached', function() {
151151
);
152152
});
153153

154-
const cachedAst = parser.parse(
154+
const cachedAst = parse(
155155
`{var0, plural,
156156
zero {{var0, number} message}
157157
one {{var0, number} message}
@@ -163,7 +163,7 @@ const cachedAst = parser.parse(
163163
suite.add(
164164
'100 x <FormattedMessage> with placeholder, cached in AST form',
165165
function() {
166-
let messages: Record<number, MessageFormatPattern> = {};
166+
let messages: Record<number, MessageFormatElement[]> = {};
167167
let formattedMessages = [];
168168
for (let i = 0, len = 100; i < len; i += 1) {
169169
messages[i] = cachedAst;

test/unit/components/html-message.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('<FormattedHTMLMessage>', () => {
122122
).find('span');
123123

124124
expect((rendered.prop('dangerouslySetInnerHTML') as any).__html).toBe(
125-
'Hello, <b>[object Object]</b>!'
125+
'Hello, <b></b>!'
126126
);
127127
});
128128
});

test/unit/format.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import IntlMessageFormat from 'intl-messageformat';
22
import * as f from '../../src/format';
3-
import parser from 'intl-messageformat-parser';
3+
import {parse} from 'intl-messageformat-parser';
44
describe('format API', () => {
55
const {NODE_ENV} = process.env;
66

@@ -25,8 +25,8 @@ describe('format API', () => {
2525
invalid: 'invalid {}',
2626
missing_value: 'missing {arg_missing}',
2727
missing_named_format: 'missing {now, date, format_missing}',
28-
ast_simple: parser.parse('hello world'),
29-
ast_var: parser.parse('hello there, {name}'),
28+
ast_simple: parse('hello world'),
29+
ast_var: parse('hello there, {name}'),
3030
},
3131

3232
formats: {

0 commit comments

Comments
 (0)