Skip to content

Commit bafc0b0

Browse files
jwilssonshellscape
authored andcommitted
Revert loose number parsing to pre-1.2.0 state. (#24)
* Revert loose number parsing to pre-1.2.0 state. When the loose option is "true", numbers with operators will now be parsed the same way as in 1.1.0. * Fix test failure Could've sworn I tested that locally
1 parent f3d9616 commit bafc0b0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/parser.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,15 @@ module.exports = class Parser {
169169
}
170170
}
171171

172-
// if ((!this.current.nodes.length || (this.current.last && this.current.last.type === 'operator')) && this.nextToken[0] === 'word') {
173-
if (this.nextToken[0] === 'word') {
174-
return this.word();
172+
if (!this.options.loose) {
173+
if (this.nextToken[0] === 'word') {
174+
return this.word();
175+
}
176+
}
177+
else {
178+
if ((!this.current.nodes.length || (this.current.last && this.current.last.type === 'operator')) && this.nextToken[0] === 'word') {
179+
return this.word();
180+
}
175181
}
176182
}
177183

test/number.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ describe('Parser → Number : Loose', () => {
153153
},
154154
{
155155
test: '5+5',
156-
expected: { value: '+5', unit: '', length: 2 }
156+
expected: { value: '5', unit: '', length: 3 }
157157
},
158158
{
159159
test: '5+-+-+-+5',
160160
expected: { value: '+5', unit: '', length: 8 }
161161
},
162162
{
163-
test: '-16px -1px -1px -16px',
164-
expected: { value: '-16', unit: 'px', length: 4 }
163+
test: '-16px -1px -1px 16px',
164+
expected: { value: '16', unit: 'px', length: 6 }
165165
}
166166
];
167167

0 commit comments

Comments
 (0)