From 145c97734f8cd9436c676096774ccc8db1f4271d Mon Sep 17 00:00:00 2001 From: 43081j <43081j@users.noreply.github.com> Date: Tue, 4 Sep 2018 20:44:21 +0100 Subject: [PATCH] ts generator: allow reserved keywords in interfaces --- scripts/generators/typescript.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/generators/typescript.js b/scripts/generators/typescript.js index d2dcd13e9fa1..0cd5ff4042e2 100644 --- a/scripts/generators/typescript.js +++ b/scripts/generators/typescript.js @@ -81,8 +81,12 @@ for (const type in t.NODE_FIELDS) { ); } - if (t.isValidIdentifier(fieldName)) { + const alphaNumeric = /^\w+$/; + + if (t.isValidIdentifier(fieldName) || alphaNumeric.test(fieldName)) { struct.push(`${fieldName}: ${typeAnnotation};`); + } else { + struct.push(`"${fieldName}": ${typeAnnotation};`); } });