scss-parser
scss-parser copied to clipboard
Error when trying to assign a new value to the 'value' property of 'Node' object
node: v16.10.0 scss-parser: 1.0.5
Trying to assign a new value to the value
property of Node
object, the same way as shown in the example in the README.md file, produces following error.
Code:
let { parse, stringify } = require('scss-parser')
// Create an AST from a string of SCSS
let ast = parse('.hello { color: $red; }')
// Modify the AST (see below for a better way to do this)
ast.value[0].value[0].value[0].value[0].value = 'world'
// Convert the modified AST back to SCSS
let scss = stringify(ast) // .world { color: $red; }
Error:
Cannot assign to read only property 'value' of object '#<Object>'
This seems to happen while using typescript. When not using typescript there is no error but the value simply remains unchanged.
This behaviour is most likely caused by this function: https://github.com/salesforce-ux/scss-parser/blob/master/lib/token-stream.js#L191
Reproduction:
https://stackblitz.com/edit/node-whjqlv?file=index.ts