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.

Commitabe7037

Browse files
committed
prettier
1 parent083f0a7 commitabe7037

File tree

4 files changed

+132
-129
lines changed

4 files changed

+132
-129
lines changed

‎package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
"bugs": {
5151
"url":"https://github.com/formatjs/babel-plugin-react-intl/issues"
5252
},
53-
"homepage":"https://github.com/formatjs/babel-plugin-react-intl#readme"
53+
"homepage":"https://github.com/formatjs/babel-plugin-react-intl#readme",
54+
"prettier": {
55+
"singleQuote":true
56+
}
5457
}

‎src/index.js‎

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
* See the accompanying LICENSE file for terms.
55
*/
66

7-
import*aspfrom"path";
8-
import{writeFileSync}from"fs";
9-
import{syncasmkdirpSync}from"mkdirp";
10-
importprintICUMessagefrom"./print-icu-message";
7+
import*aspfrom'path';
8+
import{writeFileSync}from'fs';
9+
import{syncasmkdirpSync}from'mkdirp';
10+
importprintICUMessagefrom'./print-icu-message';
1111

12-
constCOMPONENT_NAMES=["FormattedMessage","FormattedHTMLMessage"];
12+
constCOMPONENT_NAMES=['FormattedMessage','FormattedHTMLMessage'];
1313

14-
constFUNCTION_NAMES=["defineMessages"];
14+
constFUNCTION_NAMES=['defineMessages'];
1515

16-
constDESCRIPTOR_PROPS=newSet(["id","description","defaultMessage"]);
16+
constDESCRIPTOR_PROPS=newSet(['id','description','defaultMessage']);
1717

18-
constEXTRACTED=Symbol("ReactIntlExtracted");
19-
constMESSAGES=Symbol("ReactIntlMessages");
18+
constEXTRACTED=Symbol('ReactIntlExtracted');
19+
constMESSAGES=Symbol('ReactIntlMessages');
2020

2121
exportdefaultfunction({types:t}){
2222
functiongetModuleSourceName(opts){
23-
returnopts.moduleSourceName||"react-intl";
23+
returnopts.moduleSourceName||'react-intl';
2424
}
2525

2626
functionevaluatePath(path){
@@ -30,7 +30,7 @@ export default function({ types: t }) {
3030
}
3131

3232
throwpath.buildCodeFrameError(
33-
"[React Intl] Messages must be statically evaluate-able for extraction."
33+
'[React Intl] Messages must be statically evaluate-able for extraction.'
3434
);
3535
}
3636

@@ -44,13 +44,13 @@ export default function({ types: t }) {
4444

4545
functiongetMessageDescriptorValue(path){
4646
if(path.isJSXExpressionContainer()){
47-
path=path.get("expression");
47+
path=path.get('expression');
4848
}
4949

5050
// Always trim the Message Descriptor values.
5151
constdescriptorValue=evaluatePath(path);
5252

53-
if(typeofdescriptorValue==="string"){
53+
if(typeofdescriptorValue==='string'){
5454
returndescriptorValue.trim();
5555
}
5656

@@ -66,20 +66,20 @@ export default function({ types: t }) {
6666
if(
6767
isJSXSource&&
6868
messagePath.isLiteral()&&
69-
message.indexOf("\\\\")>=0
69+
message.indexOf('\\\\')>=0
7070
){
7171
throwmessagePath.buildCodeFrameError(
72-
"[React Intl] Message failed to parse."+
73-
"It looks like `\\`s were used for escaping,"+
72+
'[React Intl] Message failed to parse.'+
73+
'It looks like `\\`s were used for escaping,'+
7474
"this won't work with JSX string literals. "+
75-
"Wrap with `{}`."+
76-
"See: http://facebook.github.io/react/docs/jsx-gotchas.html"
75+
'Wrap with `{}`.'+
76+
'See: http://facebook.github.io/react/docs/jsx-gotchas.html'
7777
);
7878
}
7979

8080
throwmessagePath.buildCodeFrameError(
81-
"[React Intl] Message failed to parse."+
82-
"See: http://formatjs.io/guides/message-syntax/"+
81+
'[React Intl] Message failed to parse.'+
82+
'See: http://formatjs.io/guides/message-syntax/'+
8383
`\n${parseError}`
8484
);
8585
}
@@ -104,7 +104,7 @@ export default function({ types: t }) {
104104
Object.keys(descriptor).forEach(key=>{
105105
constvaluePath=descriptor[key];
106106

107-
if(key==="defaultMessage"){
107+
if(key==='defaultMessage'){
108108
descriptor[key]=getICUMessageValue(valuePath,{ isJSXSource});
109109
}else{
110110
descriptor[key]=getMessageDescriptorValue(valuePath);
@@ -127,7 +127,7 @@ export default function({ types: t }) {
127127

128128
if(!(id&&defaultMessage)){
129129
throwpath.buildCodeFrameError(
130-
"[React Intl] Message Descriptors require an `id` and `defaultMessage`."
130+
'[React Intl] Message Descriptors require an `id` and `defaultMessage`.'
131131
);
132132
}
133133

@@ -141,18 +141,18 @@ export default function({ types: t }) {
141141
){
142142
throwpath.buildCodeFrameError(
143143
`[React Intl] Duplicate message id: "${id}", `+
144-
"but the `description` and/or `defaultMessage` are different."
144+
'but the `description` and/or `defaultMessage` are different.'
145145
);
146146
}
147147
}
148148

149149
if(opts.enforceDescriptions){
150150
if(
151151
!description||
152-
(typeofdescription==="object"&&Object.keys(description).length<1)
152+
(typeofdescription==='object'&&Object.keys(description).length<1)
153153
){
154154
throwpath.buildCodeFrameError(
155-
"[React Intl] Message must have a `description`."
155+
'[React Intl] Message must have a `description`.'
156156
);
157157
}
158158
}
@@ -178,13 +178,13 @@ export default function({ types: t }) {
178178

179179
functionisFormatMessageCall(path){
180180
if(t.isMemberExpression(path)){
181-
constproperty=path.get("property");
181+
constproperty=path.get('property');
182182

183-
if(t.isIdentifier(property)&&property.node.name==="formatMessage"){
184-
constobject=path.get("object");
185-
constobjectProperty=object.get("property");
183+
if(t.isIdentifier(property)&&property.node.name==='formatMessage'){
184+
constobject=path.get('object');
185+
constobjectProperty=object.get('property');
186186
if(t.isIdentifier(objectProperty)){
187-
if(objectProperty.node.name==="intl"){
187+
if(objectProperty.node.name==='intl'){
188188
returntrue;
189189
}
190190
}
@@ -216,7 +216,7 @@ export default function({ types: t }) {
216216
constbasename=p.basename(filename,p.extname(filename));
217217
constmessages=file.get(MESSAGES);
218218
constdescriptors=[...messages.values()];
219-
file.metadata["react-intl"]={messages:descriptors};
219+
file.metadata['react-intl']={messages:descriptors};
220220

221221
if(opts.messagesDir&&descriptors.length>0){
222222
// Make sure the relative path is "absolute" before
@@ -225,7 +225,7 @@ export default function({ types: t }) {
225225
// Solve when the window user has symlink on the directory, because
226226
// process.cwd on windows returns the symlink root,
227227
// and filename (from babel) returns the original root
228-
if(process.platform==="win32"){
228+
if(process.platform==='win32'){
229229
const{ name}=p.parse(process.cwd());
230230
if(relativePath.includes(name)){
231231
relativePath=relativePath.slice(
@@ -237,7 +237,7 @@ export default function({ types: t }) {
237237
constmessagesFilename=p.join(
238238
opts.messagesDir,
239239
p.dirname(relativePath),
240-
basename+".json"
240+
basename+'.json'
241241
);
242242

243243
constmessagesFile=JSON.stringify(descriptors,null,2);
@@ -255,26 +255,26 @@ export default function({ types: t }) {
255255

256256
const{ file, opts}=state;
257257
constmoduleSourceName=getModuleSourceName(opts);
258-
constname=path.get("name");
258+
constname=path.get('name');
259259

260-
if(name.referencesImport(moduleSourceName,"FormattedPlural")){
260+
if(name.referencesImport(moduleSourceName,'FormattedPlural')){
261261
constwarn=file.log ?file.log.warn :console.warn;
262262
warn(
263263
`[React Intl] Line${path.node.loc.start.line}: `+
264-
"Default messages are not extracted from"+
265-
"<FormattedPlural>, use <FormattedMessage> instead."
264+
'Default messages are not extracted from'+
265+
'<FormattedPlural>, use <FormattedMessage> instead.'
266266
);
267267

268268
return;
269269
}
270270

271271
if(referencesImport(name,moduleSourceName,COMPONENT_NAMES)){
272272
constattributes=path
273-
.get("attributes")
273+
.get('attributes')
274274
.filter(attr=>attr.isJSXAttribute());
275275

276276
letdescriptor=createMessageDescriptor(
277-
attributes.map(attr=>[attr.get("name"),attr.get("value")])
277+
attributes.map(attr=>[attr.get('name'),attr.get('value')])
278278
);
279279

280280
// In order for a default message to be extracted when
@@ -296,14 +296,14 @@ export default function({ types: t }) {
296296

297297
// Remove description since it's not used at runtime.
298298
attributes.forEach(attr=>{
299-
constketPath=attr.get("name");
300-
if(getMessageDescriptorKey(ketPath)==="description"){
299+
constketPath=attr.get('name');
300+
if(getMessageDescriptorKey(ketPath)==='description'){
301301
attr.remove();
302302
}elseif(
303303
opts.overrideIdFn&&
304-
getMessageDescriptorKey(ketPath)==="id"
304+
getMessageDescriptorKey(ketPath)==='id'
305305
){
306-
attr.get("value").replaceWith(t.stringLiteral(descriptor.id));
306+
attr.get('value').replaceWith(t.stringLiteral(descriptor.id));
307307
}
308308
});
309309

@@ -315,16 +315,16 @@ export default function({ types: t }) {
315315

316316
CallExpression(path,state){
317317
constmoduleSourceName=getModuleSourceName(state.opts);
318-
constcallee=path.get("callee");
318+
constcallee=path.get('callee');
319319
const{ opts}=state;
320320

321321
functionassertObjectExpression(node){
322322
if(!(node&&node.isObjectExpression())){
323323
throwpath.buildCodeFrameError(
324324
`[React Intl] \`${callee.node.name}()\` must be `+
325-
"called with an object expression with values"+
326-
"that are React Intl Message Descriptors, also"+
327-
"defined as object expressions."
325+
'called with an object expression with values'+
326+
'that are React Intl Message Descriptors, also'+
327+
'defined as object expressions.'
328328
);
329329
}
330330
}
@@ -336,10 +336,10 @@ export default function({ types: t }) {
336336
return;
337337
}
338338

339-
constproperties=messageObj.get("properties");
339+
constproperties=messageObj.get('properties');
340340

341341
letdescriptor=createMessageDescriptor(
342-
properties.map(prop=>[prop.get("key"),prop.get("value")])
342+
properties.map(prop=>[prop.get('key'),prop.get('value')])
343343
);
344344

345345
// Evaluate the Message Descriptor values, then store it.
@@ -352,11 +352,11 @@ export default function({ types: t }) {
352352
messageObj.replaceWith(
353353
t.objectExpression([
354354
t.objectProperty(
355-
t.stringLiteral("id"),
355+
t.stringLiteral('id'),
356356
t.stringLiteral(descriptor.id)
357357
),
358358
t.objectProperty(
359-
t.stringLiteral("defaultMessage"),
359+
t.stringLiteral('defaultMessage'),
360360
t.stringLiteral(descriptor.defaultMessage)
361361
)
362362
])
@@ -367,18 +367,18 @@ export default function({ types: t }) {
367367
}
368368

369369
if(referencesImport(callee,moduleSourceName,FUNCTION_NAMES)){
370-
constmessagesObj=path.get("arguments")[0];
370+
constmessagesObj=path.get('arguments')[0];
371371

372372
assertObjectExpression(messagesObj);
373373

374374
messagesObj
375-
.get("properties")
376-
.map(prop=>prop.get("value"))
375+
.get('properties')
376+
.map(prop=>prop.get('value'))
377377
.forEach(processMessageObject);
378378
}
379379

380380
if(isFormatMessageCall(callee)){
381-
constmessagesObj=path.get("arguments")[0];
381+
constmessagesObj=path.get('arguments')[0];
382382
processMessageObject(messagesObj);
383383
}
384384
}

‎src/print-icu-message.js‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* See the accompanying LICENSE file for terms.
55
*/
66

7-
import{parse}from"intl-messageformat-parser";
7+
import{parse}from'intl-messageformat-parser';
88

99
constESCAPED_CHARS={
10-
"\\":"\\\\",
11-
"\\#":"\\#",
12-
"{":"\\{",
13-
"}":"\\}"
10+
'\\':'\\\\',
11+
'\\#':'\\#',
12+
'{':'\\{',
13+
'}':'\\}'
1414
};
1515

1616
constESAPE_CHARS_REGEXP=/\\#|[{}\\]/g;
@@ -22,7 +22,7 @@ export default function(message) {
2222

2323
functionprintICUMessage(ast){
2424
letprintedNodes=ast.elements.map(node=>{
25-
if(node.type==="messageTextElement"){
25+
if(node.type==='messageTextElement'){
2626
returnprintMessageTextASTNode(node);
2727
}
2828

@@ -31,30 +31,30 @@ function printICUMessage(ast) {
3131
}
3232

3333
switch(getArgumentType(node.format)){
34-
case"number":
35-
case"date":
36-
case"time":
34+
case'number':
35+
case'date':
36+
case'time':
3737
returnprintSimpleFormatASTNode(node);
3838

39-
case"plural":
40-
case"selectordinal":
41-
case"select":
39+
case'plural':
40+
case'selectordinal':
41+
case'select':
4242
returnprintOptionalFormatASTNode(node);
4343
}
4444
});
4545

46-
returnprintedNodes.join("");
46+
returnprintedNodes.join('');
4747
}
4848

4949
functiongetArgumentType(format){
5050
const{ type, ordinal}=format;
5151

5252
// Special-case ordinal plurals to use `selectordinal` instead of `plural`.
53-
if(type==="pluralFormat"&&ordinal){
54-
return"selectordinal";
53+
if(type==='pluralFormat'&&ordinal){
54+
return'selectordinal';
5555
}
5656

57-
returntype.replace(/Format$/,"").toLowerCase();
57+
returntype.replace(/Format$/,'').toLowerCase();
5858
}
5959

6060
functionprintMessageTextASTNode({ value}){
@@ -63,19 +63,19 @@ function printMessageTextASTNode({ value }) {
6363

6464
functionprintSimpleFormatASTNode({ id, format}){
6565
letargumentType=getArgumentType(format);
66-
letstyle=format.style ?`,${format.style}` :"";
66+
letstyle=format.style ?`,${format.style}` :'';
6767

6868
return`{${id},${argumentType}${style}}`;
6969
}
7070

7171
functionprintOptionalFormatASTNode({ id, format}){
7272
letargumentType=getArgumentType(format);
73-
letoffset=format.offset ?`, offset:${format.offset}` :"";
73+
letoffset=format.offset ?`, offset:${format.offset}` :'';
7474

7575
letoptions=format.options.map(option=>{
7676
letoptionValue=printICUMessage(option.value);
7777
return`${option.selector} {${optionValue}}`;
7878
});
7979

80-
return`{${id},${argumentType}${offset},${options.join("")}}`;
80+
return`{${id},${argumentType}${offset},${options.join('')}}`;
8181
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp