Allow escaped " literals in the SyntaxScopeMap

In order to pass a quote literal to the postcss-selector-parser, it 
needs to be escaped. However, this escaping is not removed by the parser 
in the yielded value token, so in this commit I replace any escaped 
quote literals with unescaped quotes after we trim the outer quotes off 
of the string.
This commit is contained in:
Nathan Sobo
2019-05-14 17:17:49 -06:00
parent 50d890abea
commit 765d5122c3
2 changed files with 4 additions and 2 deletions

View File

@@ -49,13 +49,15 @@ describe('SyntaxScopeMap', () => {
const map = new SyntaxScopeMap({
'"b"': 'w',
'a > "b"': 'x',
'a > "b":nth-child(1)': 'y'
'a > "b":nth-child(1)': 'y',
'"\\""': 'z'
})
expect(map.get(['b'], [0], true)).toBe(undefined)
expect(map.get(['b'], [0], false)).toBe('w')
expect(map.get(['a', 'b'], [0, 0], false)).toBe('x')
expect(map.get(['a', 'b'], [0, 1], false)).toBe('y')
expect(map.get(['a', '"'], [0, 1], false)).toBe('z')
})
it('supports the wildcard selector', () => {

View File

@@ -36,7 +36,7 @@ class SyntaxScopeMap {
case 'string':
if (!currentTable) currentTable = this.anonymousScopeTable
const value = termNode.value.slice(1, -1)
const value = termNode.value.slice(1, -1).replace(/\\"/g, '"')
if (!currentTable[value]) currentTable[value] = {}
currentTable = currentTable[value]
if (currentIndexValue != null) {