Skip to content

Commit

Permalink
Fix interpolated at-rule parsing (#133)
Browse files Browse the repository at this point in the history
Closes #131
  • Loading branch information
nex3 authored Oct 29, 2021
1 parent e5ffc96 commit c021e23
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/scss-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ class ScssParser extends Parser {
}
}

atrule(token) {
let name = token[1]
let prev = token
while (!this.tokenizer.endOfFile()) {
let next = this.tokenizer.nextToken()
if (next[0] === 'word' && next[2] === prev[3] + 1) {
name += next[1]
prev = next
} else {
this.tokenizer.back(next)
break
}
}

super.atrule(['at-word', name, token[2], prev[3]])
}

raw(node, prop, tokens) {
super.raw(node, prop, tokens)
if (node.raws[prop]) {
Expand Down
25 changes: 25 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,33 @@ it('parses interpolation inside interpolation', () => {
expect(root.first.value).toEqual('#{"#{&}__column"}')
})

it("parses interpolation that's the entire at-rule", () => {
let root = parse('@#{$var} param { }')
expect(root.first.name).toEqual('#{$var}')
expect(root.first.params).toEqual('param')
})

it('parses interpolation at the beginning of at-rule', () => {
let root = parse('@#{$var}suffix param { }')
expect(root.first.name).toEqual('#{$var}suffix')
expect(root.first.params).toEqual('param')
})

it('parses interpolation within at-rule', () => {
let root = parse('@before#{$var}after param { }')
expect(root.first.name).toEqual('before#{$var}after')
expect(root.first.params).toEqual('param')
})

it('parses interpolation right after at-rule', () => {
let root = parse('@media#{$var} { }')
expect(root.first.name).toEqual('media#{$var}')
expect(root.first.params).toEqual('')
})

it('parses interpolation in at-rule value', () => {
let root = parse('@media #{$var} { }')
expect(root.first.name).toEqual('media')
expect(root.first.params).toEqual('#{$var}')
})

Expand Down

0 comments on commit c021e23

Please sign in to comment.