Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commitfc4dddd

Browse files
swernerxlonglho
authored andcommitted
Add support for processingintl.formatMessage when injection is used. (#165)
* Updated deps* Added failing tests for formatMessage calls.* Added support for extracting from intl.formatMessage()
1 parent2e9de26 commitfc4dddd

File tree

7 files changed

+1553
-1014
lines changed

7 files changed

+1553
-1014
lines changed

‎.eslintrc‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion":6,
3+
"ecmaVersion":2018,
44
"sourceType": "module",
55
"ecmaFeatures": {
6-
"jsx": true,
7-
"experimentalObjectRestSpread": true
6+
"jsx": true
87
}
98
},
109
"extends": "eslint:recommended",

‎package.json‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010
"main":"lib/index.js",
1111
"author":"Eric Ferraiuolo <edf@ericf.me>",
1212
"dependencies": {
13-
"@babel/runtime":"^7.0.0",
14-
"intl-messageformat-parser":"^1.2.0",
13+
"@babel/runtime":"^7.3.1",
14+
"intl-messageformat-parser":"^1.4.0",
1515
"mkdirp":"^0.5.1"
1616
},
1717
"devDependencies": {
18-
"@babel/cli":"^7.0.0",
19-
"@babel/core":"^7.0.0",
20-
"@babel/node":"^7.0.0",
21-
"@babel/plugin-proposal-object-rest-spread":"^7.0.0",
22-
"@babel/plugin-transform-runtime":"^7.0.0",
23-
"@babel/preset-env":"^7.0.0",
18+
"@babel/cli":"^7.2.3",
19+
"@babel/core":"^7.2.2",
20+
"@babel/node":"^7.2.2",
21+
"@babel/plugin-proposal-object-rest-spread":"^7.3.1",
22+
"@babel/plugin-transform-runtime":"^7.2.0",
23+
"@babel/preset-env":"^7.3.1",
2424
"@babel/preset-react":"^7.0.0",
2525
"@babel/register":"^7.0.0",
26-
"babel-plugin-espower":"^3.0.0",
27-
"cross-env":"^3.1.4",
28-
"eslint":"^3.14.1",
29-
"eslint-plugin-react":"^6.1.2",
30-
"mocha":"^3.0.2",
31-
"power-assert":"^1.4.1",
32-
"rimraf":"^2.4.3",
26+
"babel-plugin-espower":"^3.0.1",
27+
"cross-env":"^5.2.0",
28+
"eslint":"^5.12.1",
29+
"eslint-plugin-react":"^7.12.4",
30+
"mocha":"^5.2.0",
31+
"power-assert":"^1.6.1",
32+
"rimraf":"^2.6.3",
3333
"uuid":"^3.3.2"
3434
},
3535
"scripts": {

‎src/index.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ export default function ({types: t}) {
168168
returnimportedNames.some((name)=>path.referencesImport(mod,name));
169169
}
170170

171+
functionisFormatMessageCall(path){
172+
if(t.isMemberExpression(path)){
173+
constproperty=path.get('property');
174+
175+
if(t.isIdentifier(property)&&property.node.name==='formatMessage'){
176+
constobject=path.get('object');
177+
constobjectProperty=object.get('property');
178+
if(t.isIdentifier(objectProperty)){
179+
if(objectProperty.node.name==='intl'){
180+
returntrue;
181+
}
182+
}
183+
}
184+
}
185+
186+
returnfalse;
187+
}
188+
171189
functiontagAsExtracted(path){
172190
path.node[EXTRACTED]=true;
173191
}
@@ -336,6 +354,11 @@ export default function ({types: t}) {
336354
.map((prop)=>prop.get('value'))
337355
.forEach(processMessageObject);
338356
}
357+
358+
if(isFormatMessageCall(callee)){
359+
constmessagesObj=path.get('arguments')[0];
360+
processMessageObject(messagesObj);
361+
}
339362
},
340363
},
341364
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
importReact,{Component}from'react';
2+
import{injectIntl}from'react-intl';
3+
4+
classFooextendsComponent{
5+
render(){
6+
constmsgs={
7+
baz:this.props.intl.formatMessage({
8+
id:'foo.bar.baz',
9+
defaultMessage:'Hello World!',
10+
description:'The default message',
11+
}),
12+
biff:this.props.intl.formatMessage({
13+
id:'foo.bar.biff',
14+
defaultMessage:'Hello Nurse!',
15+
description:'Another message',
16+
}),
17+
};
18+
19+
return(
20+
<div>
21+
<h1>{msgs.header}</h1>
22+
<p>{msgs.content}</p>
23+
</div>
24+
);
25+
}
26+
}
27+
28+
exportdefaultinjectIntl(Foo);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports,"__esModule",{
4+
value:true
5+
});
6+
exports.default=void0;
7+
8+
var_react=_interopRequireWildcard(require("react"));
9+
10+
var_reactIntl=require("react-intl");
11+
12+
function_interopRequireWildcard(obj){if(obj&&obj.__esModule){returnobj;}else{varnewObj={};if(obj!=null){for(varkeyinobj){if(Object.prototype.hasOwnProperty.call(obj,key)){vardesc=Object.defineProperty&&Object.getOwnPropertyDescriptor ?Object.getOwnPropertyDescriptor(obj,key) :{};if(desc.get||desc.set){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}}newObj.default=obj;returnnewObj;}}
13+
14+
function_typeof(obj){if(typeofSymbol==="function"&&typeofSymbol.iterator==="symbol"){_typeof=function_typeof(obj){returntypeofobj;};}else{_typeof=function_typeof(obj){returnobj&&typeofSymbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype ?"symbol" :typeofobj;};}return_typeof(obj);}
15+
16+
function_classCallCheck(instance,Constructor){if(!(instanceinstanceofConstructor)){thrownewTypeError("Cannot call a class as a function");}}
17+
18+
function_defineProperties(target,props){for(vari=0;i<props.length;i++){vardescriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"indescriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}
19+
20+
function_createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);returnConstructor;}
21+
22+
function_possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeofcall==="function")){returncall;}return_assertThisInitialized(self);}
23+
24+
function_assertThisInitialized(self){if(self===void0){thrownewReferenceError("this hasn't been initialised - super() hasn't been called");}returnself;}
25+
26+
function_getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf ?Object.getPrototypeOf :function_getPrototypeOf(o){returno.__proto__||Object.getPrototypeOf(o);};return_getPrototypeOf(o);}
27+
28+
function_inherits(subClass,superClass){if(typeofsuperClass!=="function"&&superClass!==null){thrownewTypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}
29+
30+
function_setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function_setPrototypeOf(o,p){o.__proto__=p;returno;};return_setPrototypeOf(o,p);}
31+
32+
varFoo=
33+
/*#__PURE__*/
34+
function(_Component){
35+
_inherits(Foo,_Component);
36+
37+
functionFoo(){
38+
_classCallCheck(this,Foo);
39+
40+
return_possibleConstructorReturn(this,_getPrototypeOf(Foo).apply(this,arguments));
41+
}
42+
43+
_createClass(Foo,[{
44+
key:"render",
45+
value:functionrender(){
46+
varmsgs={
47+
baz:this.props.intl.formatMessage({
48+
"id":"foo.bar.baz",
49+
"defaultMessage":"Hello World!"
50+
}),
51+
biff:this.props.intl.formatMessage({
52+
"id":"foo.bar.biff",
53+
"defaultMessage":"Hello Nurse!"
54+
})
55+
};
56+
return_react.default.createElement("div",null,_react.default.createElement("h1",null,msgs.header),_react.default.createElement("p",null,msgs.content));
57+
}
58+
}]);
59+
60+
returnFoo;
61+
}(_react.Component);
62+
63+
var_default=(0,_reactIntl.injectIntl)(Foo);
64+
65+
exports.default=_default;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"id":"foo.bar.baz",
4+
"description":"The default message",
5+
"defaultMessage":"Hello World!"
6+
},
7+
{
8+
"id":"foo.bar.biff",
9+
"description":"Another message",
10+
"defaultMessage":"Hello Nurse!"
11+
}
12+
]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp