Permalink
Browse files

renderer: be aware of reserved keywords

  • Loading branch information...
1 parent ff55586 commit 771e3e73aac0f079742444634a5fc45c10dedf8f @indutny committed Nov 16, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 lib/spoon/renderer.js
View
@@ -305,8 +305,20 @@ Renderer.prototype.renderMethod = function renderMethod(args) {
return ['call', this.renderGetprop(args.slice(0, 2)), args.slice(2)];
};
+var reserved = [
+ 'break', 'case', 'catch', 'continue', 'debugger', 'default',
+ 'delete', 'do', 'else', 'finally', 'for', 'function', 'function', 'if',
+ 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try',
+ 'typeof', 'var', 'void', 'while', 'with', 'class', 'enum', 'export',
+ 'extends', 'import', 'super', 'implements', 'interface', 'let',
+ 'package', 'private', 'protected', 'public', 'static', 'yield', 'null',
+ 'true', 'false', 'undefined'
+];
+reserved = new RegExp('^(' + reserved.join('|') + ')$');
+
Renderer.prototype.renderGetprop = function renderGetprop(args) {
- if (args[1][0] === 'string' && /^[$_a-z][$_a-z0-9]*$/i.test(args[1][1])) {
+ if (args[1][0] === 'string' && /^[$_a-z][$_a-z0-9]*$/i.test(args[1][1]) &&
+ !reserved.test(args[1][1])) {
return ['dot', args[0], args[1][1]];
}
return ['sub', args[0], args[1]];

0 comments on commit 771e3e7

Please sign in to comment.