Skip to content

Commit 4db60e4

Browse files
committed
Update prettier to match main repo
1 parent 16d02a4 commit 4db60e4

13 files changed

+726
-727
lines changed

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5"
5+
}

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
language: node_js
32
dist: trusty
43
node_js:

src/TokenStream.js

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
const SYMBOL_MATCH = "SYMBOL_MATCH";
1+
const SYMBOL_MATCH = 'SYMBOL_MATCH'
22

33
module.exports = class TokenStream {
44
constructor(nodes, parent) {
5-
this.index = 0;
6-
this.nodes = nodes;
7-
this.functionName = parent != null ? parent.value : null;
8-
this.lastValue = null;
9-
this.rewindIndex = -1;
5+
this.index = 0
6+
this.nodes = nodes
7+
this.functionName = parent != null ? parent.value : null
8+
this.lastValue = null
9+
this.rewindIndex = -1
1010
}
1111

1212
hasTokens() {
13-
return this.index <= this.nodes.length - 1;
13+
return this.index <= this.nodes.length - 1
1414
}
1515

1616
[SYMBOL_MATCH](...tokenDescriptors) {
17-
if (!this.hasTokens()) return null;
17+
if (!this.hasTokens()) return null
1818

19-
const node = this.nodes[this.index];
19+
const node = this.nodes[this.index]
2020

2121
for (let i = 0; i < tokenDescriptors.length; i += 1) {
22-
const tokenDescriptor = tokenDescriptors[i];
23-
const value = tokenDescriptor(node);
22+
const tokenDescriptor = tokenDescriptors[i]
23+
const value = tokenDescriptor(node)
2424
if (value !== null) {
25-
this.index += 1;
26-
this.lastValue = value;
27-
return value;
25+
this.index += 1
26+
this.lastValue = value
27+
return value
2828
}
2929
}
3030

31-
return null;
31+
return null
3232
}
3333

3434
matches(...tokenDescriptors) {
35-
return this[SYMBOL_MATCH](...tokenDescriptors) !== null;
35+
return this[SYMBOL_MATCH](...tokenDescriptors) !== null
3636
}
3737

3838
expect(...tokenDescriptors) {
39-
const value = this[SYMBOL_MATCH](...tokenDescriptors);
40-
return value !== null ? value : this.throw();
39+
const value = this[SYMBOL_MATCH](...tokenDescriptors)
40+
return value !== null ? value : this.throw()
4141
}
4242

4343
matchesFunction() {
44-
const node = this.nodes[this.index];
45-
if (node.type !== "function") return null;
46-
const value = new TokenStream(node.nodes, node);
47-
this.index += 1;
48-
this.lastValue = null;
49-
return value;
44+
const node = this.nodes[this.index]
45+
if (node.type !== 'function') return null
46+
const value = new TokenStream(node.nodes, node)
47+
this.index += 1
48+
this.lastValue = null
49+
return value
5050
}
5151

5252
expectFunction() {
53-
const value = this.matchesFunction();
54-
return value !== null ? value : this.throw();
53+
const value = this.matchesFunction()
54+
return value !== null ? value : this.throw()
5555
}
5656

5757
expectEmpty() {
58-
if (this.hasTokens()) this.throw();
58+
if (this.hasTokens()) this.throw()
5959
}
6060

6161
throw() {
62-
throw new Error(`Unexpected token type: ${this.nodes[this.index].type}`);
62+
throw new Error(`Unexpected token type: ${this.nodes[this.index].type}`)
6363
}
6464

6565
saveRewindPoint() {
66-
this.rewindIndex = this.index;
66+
this.rewindIndex = this.index
6767
}
6868

6969
rewind() {
70-
if (this.rewindIndex === -1) throw new Error("Internal error");
71-
this.index = this.rewindIndex;
72-
this.lastValue = null;
70+
if (this.rewindIndex === -1) throw new Error('Internal error')
71+
this.index = this.rewindIndex
72+
this.lastValue = null
7373
}
74-
};
74+
}

src/index.js

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
/* eslint-disable no-param-reassign */
2-
const parse = require("postcss-value-parser");
3-
const camelizeStyleName = require("fbjs/lib/camelizeStyleName");
4-
const transforms = require("./transforms");
5-
const TokenStream = require("./TokenStream");
2+
const parse = require('postcss-value-parser')
3+
const camelizeStyleName = require('fbjs/lib/camelizeStyleName')
4+
const transforms = require('./transforms')
5+
const TokenStream = require('./TokenStream')
66

77
// Note if this is wrong, you'll need to change tokenTypes.js too
8-
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i;
9-
const boolRe = /^true|false$/i;
10-
const nullRe = /^null$/i;
11-
const undefinedRe = /^undefined$/i;
8+
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i
9+
const boolRe = /^true|false$/i
10+
const nullRe = /^null$/i
11+
const undefinedRe = /^undefined$/i
1212

1313
// Undocumented export
1414
export const transformRawValue = input => {
15-
const value = input.trim();
15+
const value = input.trim()
1616

17-
const numberMatch = value.match(numberOrLengthRe);
18-
if (numberMatch !== null) return Number(numberMatch[1]);
17+
const numberMatch = value.match(numberOrLengthRe)
18+
if (numberMatch !== null) return Number(numberMatch[1])
1919

20-
const boolMatch = input.match(boolRe);
21-
if (boolMatch !== null) return boolMatch[0].toLowerCase() === "true";
20+
const boolMatch = input.match(boolRe)
21+
if (boolMatch !== null) return boolMatch[0].toLowerCase() === 'true'
2222

23-
const nullMatch = input.match(nullRe);
24-
if (nullMatch !== null) return null;
23+
const nullMatch = input.match(nullRe)
24+
if (nullMatch !== null) return null
2525

26-
const undefinedMatch = input.match(undefinedRe);
27-
if (undefinedMatch !== null) return undefined;
26+
const undefinedMatch = input.match(undefinedRe)
27+
if (undefinedMatch !== null) return undefined
2828

29-
return value;
30-
};
29+
return value
30+
}
3131

3232
const baseTransformShorthandValue = (propName, inputValue) => {
33-
const ast = parse(inputValue.trim());
34-
const tokenStream = new TokenStream(ast.nodes);
35-
return transforms[propName](tokenStream);
36-
};
33+
const ast = parse(inputValue.trim())
34+
const tokenStream = new TokenStream(ast.nodes)
35+
return transforms[propName](tokenStream)
36+
}
3737

3838
const transformShorthandValue =
39-
process.env.NODE_ENV === "production"
39+
process.env.NODE_ENV === 'production'
4040
? baseTransformShorthandValue
4141
: (propName, inputValue) => {
4242
try {
43-
return baseTransformShorthandValue(propName, inputValue);
43+
return baseTransformShorthandValue(propName, inputValue)
4444
} catch (e) {
4545
throw new Error(
4646
`Failed to parse declaration "${propName}: ${inputValue}"`
47-
);
47+
)
4848
}
49-
};
49+
}
5050

5151
export const getStylesForProperty = (propName, inputValue, allowShorthand) => {
52-
const isRawValue = allowShorthand === false || !(propName in transforms);
52+
const isRawValue = allowShorthand === false || !(propName in transforms)
5353
const propValue = isRawValue
5454
? transformRawValue(inputValue)
55-
: transformShorthandValue(propName, inputValue.trim());
55+
: transformShorthandValue(propName, inputValue.trim())
5656

5757
return propValue && propValue.$merge
5858
? propValue.$merge
59-
: { [propName]: propValue };
60-
};
59+
: { [propName]: propValue }
60+
}
6161

62-
export const getPropertyName = camelizeStyleName;
62+
export const getPropertyName = camelizeStyleName
6363

6464
export default (rules, shorthandBlacklist = []) =>
6565
rules.reduce((accum, rule) => {
66-
const propertyName = getPropertyName(rule[0]);
67-
const value = rule[1];
68-
const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1;
66+
const propertyName = getPropertyName(rule[0])
67+
const value = rule[1]
68+
const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1
6969
return Object.assign(
7070
accum,
7171
getStylesForProperty(propertyName, value, allowShorthand)
72-
);
73-
}, {});
72+
)
73+
}, {})

0 commit comments

Comments
 (0)