Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created September 7, 2012 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregglind/3668391 to your computer and use it in GitHub Desktop.
Save gregglind/3668391 to your computer and use it in GitHub Desktop.
Reflect.parse for ObjectPattern
$ brew install spidermonkey
$ /usr/local/bin/js
js> print(JSON.stringify(Reflect.parse("const {a,b} = {}"),null,2) )
{
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
},
"source": null
},
"type": "Program",
"body": [
{
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
},
"source": null
},
"type": "VariableDeclaration",
"kind": "const",
"declarations": [
{
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 16
},
"source": null
},
"type": "VariableDeclarator",
"id": {
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 11
},
"source": null
},
"type": "ObjectPattern",
"properties": [
{
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"source": null
},
"type": "Property",
"key": {
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"source": null
},
"type": "Identifier",
"name": "a"
},
"value": {
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"source": null
},
"type": "Identifier",
"name": "a"
},
"kind": "init"
},
{
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"source": null
},
"type": "Property",
"key": {
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"source": null
},
"type": "Identifier",
"name": "b"
},
"value": {
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"source": null
},
"type": "Identifier",
"name": "b"
},
"kind": "init"
}
]
},
"init": {
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 16
},
"source": null
},
"type": "ObjectExpression",
"properties": []
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment