From 6eafc21c71727242c33b2ce1db1332f8d51117ab Mon Sep 17 00:00:00 2001 From: Oskar Haarklou Veileborg Date: Tue, 26 Aug 2025 13:48:44 +0200 Subject: [PATCH] Define `type` property on `SyntaxNode` subclasses with `defineProperty` Since `SyntaxNode` defines `type` as an accessor property, the write to `nodeSubclass.prototype.type` is silently swallowed. We can work around this by defining the type with `Object.defineProperty`. --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9a57b36..be05e65 100644 --- a/index.js +++ b/index.js @@ -894,7 +894,10 @@ function initializeLanguageNodeClasses(language) { const className = camelCase(typeName, true) + 'Node'; const nodeSubclass = eval(`class ${className} extends SyntaxNode {${classBody}}; ${className}`); - nodeSubclass.prototype.type = typeName; + Object.defineProperty(nodeSubclass.prototype, 'type', { + value: typeName, + enumerable: true, + }); nodeSubclass.prototype.fields = Object.freeze(fieldNames.sort()) nodeSubclasses[id] = nodeSubclass; }