From 252660f2485d4e033dc564413cde12af1a9b6c1b Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Mon, 10 Sep 2018 15:22:36 +0100 Subject: [PATCH] ts generator: allow reserved keywords in interfaces (#8627) --- 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};`); } });