- Node Version: 8.3.0
- NPM Version: 5.3.0
- postcss-values-parser Version: 1.3.0
This issue is regarding a problem with:
Actual Behavior
Parsed as:
StringNode {
value: 'a #{'
}
NumberNode {
value: '1'
}
StringNode {
value: '} b #{2} c'
}
Expected Behavior
Proposal:
Similar to how Babylon parses template literals in JavaScript: astexplorer
Something like this:
InterpolationStringNode {
expressions: [
StringNode {
value: '1'
},
NumberNode {
value: '2'
}
],
quasis: [
InterpolationStringElementNode {
value: 'a '
},
InterpolationStringElementNode {
value: ' b '
},
InterpolationStringElementNode {
value: ' c'
}
]
}
(The "expressions" and "quasis" names comes from Babylon’s AST. I made up "InterpolationStringNode". I don’t care about what they’re called.)
When you encounter #{ in a string
- Push the string so far to
quasis
- Recursively parse with postcss-values-parser until the next unbalanced
}. (Error handling, if no ending } is found throw TokenizeError: Unclosed interpolation or something.)
- Start to parse as a string again (until the end quote or the next
#{).
Notes:
- Interpolations can contain any expression, even another string with
interpolations (recursively).
- It is possible to escape interpolations:
"\#{1}" is a single StringNode.
How can we reproduce the behavior?
const parse = require("postcss-values-parser")
const test = '"a #{"1"} b #{2} c"'
const ast = parse(test, {loose: true}).parse()
console.dir(ast, {colors: true, depth: null})
Related
This issue is regarding a problem with:
Actual Behavior
Parsed as:
Expected Behavior
Proposal:
Similar to how Babylon parses template literals in JavaScript: astexplorer
Something like this:
(The "expressions" and "quasis" names comes from Babylon’s AST. I made up "InterpolationStringNode". I don’t care about what they’re called.)
When you encounter
#{in a stringquasis}. (Error handling, if no ending}is found throwTokenizeError: Unclosed interpolationor something.)#{).Notes:
interpolations (recursively).
"\#{1}"is a singleStringNode.How can we reproduce the behavior?
Related