Skip to content

Commit

Permalink
Fix empty custom property parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jan 31, 2022
1 parent 373b6c5 commit be42a7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
32 changes: 21 additions & 11 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ class Parser {
if (brackets.length > 0) this.unclosedBracket(bracket)

if (end && colon) {
while (tokens.length) {
token = tokens[tokens.length - 1][0]
if (token !== 'space' && token !== 'comment') break
this.tokenizer.back(tokens.pop())
if (!customProperty) {
while (tokens.length) {
token = tokens[tokens.length - 1][0]
if (token !== 'space' && token !== 'comment') break
this.tokenizer.back(tokens.pop())
}
}
this.decl(tokens, customProperty)
} else {
Expand Down Expand Up @@ -208,7 +210,15 @@ class Parser {
node.raws.before += node.prop[0]
node.prop = node.prop.slice(1)
}
let firstSpaces = this.spacesAndCommentsFromStart(tokens)

let firstSpaces = []
let next
while (tokens.length) {
next = tokens[0][0]
if (next !== 'space' && next !== 'comment') break
firstSpaces.push(tokens.shift())
}

this.precheckMissedSemicolon(tokens)

for (let i = tokens.length - 1; i >= 0; i--) {
Expand Down Expand Up @@ -242,12 +252,12 @@ class Parser {
}

let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment')
this.raw(node, 'value', tokens)

if (hasWord) {
node.raws.between += firstSpaces
} else {
node.value = firstSpaces + node.value
node.raws.between += firstSpaces.map(i => i[1]).join('')
firstSpaces = []
}
this.raw(node, 'value', firstSpaces.concat(tokens), customProperty)

if (node.value.includes(':') && !customProperty) {
this.checkMissedSemicolon(tokens)
Expand Down Expand Up @@ -395,7 +405,7 @@ class Parser {
if (node.type !== 'comment') this.semicolon = false
}

raw(node, prop, tokens) {
raw(node, prop, tokens, customProperty) {
let token, type
let length = tokens.length
let value = ''
Expand All @@ -405,7 +415,7 @@ class Parser {
for (let i = 0; i < length; i += 1) {
token = tokens[i]
type = token[0]
if (type === 'space' && i === length - 1) {
if (type === 'space' && i === length - 1 && !customProperty) {
clean = false
} else if (type === 'comment') {
prev = tokens[i - 1]
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be42a7c

Please sign in to comment.