Skip to content

Commit 2a3ecbe

Browse files
committed
Pass the NodePath object to extractSymbol so it can infer const from VariableDeclarator's parents
1 parent 6a69b14 commit 2a3ecbe

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/webdoc-parser/src/symbols-babel/build-symbol-tree.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default function buildSymbolTree(
186186
let idoc;
187187

188188
try {
189-
idoc = captureSymbols(nodePath.node, scope);
189+
idoc = captureSymbols(nodePath, scope);
190190
} catch (e) {
191191
console.error(ancestorStack);
192192
console.log(node);
@@ -255,10 +255,11 @@ export default function buildSymbolTree(
255255
// them as a child of parent.
256256
//
257257
// The returned symbol is the one backed by the AST node.
258-
function captureSymbols(node: Node, parent: Symbol): ?Symbol {
258+
function captureSymbols(nodePath: NodePath, parent: Symbol): ?Symbol {
259+
const node = nodePath.node;
259260
const symbolInfo = {};
260261

261-
extractSymbol(node, parent, symbolInfo);
262+
extractSymbol(nodePath, parent, symbolInfo);
262263

263264
let {
264265
name: simpleName,

packages/webdoc-parser/src/symbols-babel/extract-symbol.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type FunctionExpression,
99
type MemberExpression,
1010
type Node,
11+
type NodePath,
1112
type VariableDeclarator,
1213
isArrowFunctionExpression,
1314
isAssignmentExpression,
@@ -54,7 +55,7 @@ import {
5455
// + Set the appopriate flags
5556
// + Set isInit & initComment if the symbol has a initializer child
5657
export default function extractSymbol(
57-
node: Node,
58+
nodePath: NodePath,
5859
parent: Symbol,
5960
out: {
6061
name?: ?string,
@@ -65,6 +66,8 @@ export default function extractSymbol(
6566
init?: ?Node
6667
},
6768
): void {
69+
const node = nodePath.node;
70+
6871
let name;
6972
let flags = out.flags || 0;
7073
let isInit = false;
@@ -174,6 +177,11 @@ export default function extractSymbol(
174177
} else if (isVariableDeclarator(node)) {
175178
name = node.id.name;
176179
init = resolveInit(node);
180+
181+
// Variables defined with the const keyword are inferred to be readonly.
182+
if (nodePath.parent && nodePath.parent.kind === "const") {
183+
nodeSymbol.meta.readonly = true;
184+
}
177185
} else {// ObjectProperty
178186
name = node.key.name;
179187
init = node.value;

0 commit comments

Comments
 (0)