diff options
author | Christian Schneider | 2008-07-28 15:20:54 +0000 |
---|---|---|
committer | Christian Schneider | 2008-07-28 15:20:54 +0000 |
commit | 03443412d7038a8a68da1137ea7e6b38fdbc728c (patch) | |
tree | 3c0172544631b3175f8f9b8d9cdf026de82346ce /itjs.class | |
parent | 92e07b4f66121d0509acf2931e084b7a62dc0ee2 (diff) | |
download | itools-03443412d7038a8a68da1137ea7e6b38fdbc728c.tar.gz itools-03443412d7038a8a68da1137ea7e6b38fdbc728c.tar.bz2 itools-03443412d7038a8a68da1137ea7e6b38fdbc728c.zip |
Quote identifier if it is a javascript reserved word
Diffstat (limited to 'itjs.class')
-rw-r--r-- | itjs.class | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -65,6 +65,7 @@ function serialize($values, $envelope = false) function encode($values) { $texts = ($values === array_values($values)) ? "[]0 " : "{}1\n"; # Numerical or associative array + static $jskeyword = array("abstract" => 1, "boolean" => 1, "break" => 1, "byte" => 1, "case" => 1, "catch" => 1, "char" => 1, "class" => 1, "const" => 1, "continue" => 1, "debugger" => 1, "default" => 1, "delete" => 1, "do" => 1, "double" => 1, "each" => 1, "else" => 1, "enum" => 1, "export" => 1, "extends" => 1, "false" => 1, "final" => 1, "finally" => 1, "float" => 1, "for" => 1, "function" => 1, "goto" => 1, "if" => 1, "implements" => 1, "import" => 1, "in" => 1, "instanceof" => 1, "int" => 1, "interface" => 1, "long" => 1, "namespace" => 1, "native" => 1, "new" => 1, "null" => 1, "package" => 1, "private" => 1, "protected" => 1, "public" => 1, "return" => 1, "short" => 1, "static" => 1, "super" => 1, "switch" => 1, "synchronized" => 1, "this" => 1, "throw" => 1, "throws" => 1, "transient" => 1, "true" => 1, "try" => 1, "typeof" => 1, "var" => 1, "void" => 1, "volatile" => 1, "while" => 1, "with" => 1, "xml" => 1); $result = $texts{0}; @@ -74,7 +75,7 @@ function encode($values) if ($texts{2}) { - if (!preg_match('/^[a-z_]\w*$/i', $key)) + if ($jskeyword[$key] || !preg_match('/^[a-z_]\w*$/i', $key)) $key = "'$key'"; $result .= "$key:"; |