summaryrefslogtreecommitdiff
path: root/src/Language/ECMAScript3/Syntax/Arbitrary.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/ECMAScript3/Syntax/Arbitrary.hs')
-rw-r--r--src/Language/ECMAScript3/Syntax/Arbitrary.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Language/ECMAScript3/Syntax/Arbitrary.hs b/src/Language/ECMAScript3/Syntax/Arbitrary.hs
index 8354897..a05e348 100644
--- a/src/Language/ECMAScript3/Syntax/Arbitrary.hs
+++ b/src/Language/ECMAScript3/Syntax/Arbitrary.hs
@@ -267,10 +267,17 @@ identifierFixup :: Id a -> Id a
identifierFixup (Id a n) = Id a $ identifierNameFixup n
-- | Renames empty identifiers, as well as identifiers that are
--- keywords or future reserved words by prepending a '_' to them
+-- keywords or future reserved words by prepending a '_' to them. Also
+-- substitutes illegal characters with a "_" as well.
identifierNameFixup :: String -> String
-identifierNameFixup name = if isValidIdentifierName name then name
- else '_':name
+identifierNameFixup s =
+ let fixStart c = if isValidIdStart c then c else '_'
+ fixPart c = if isValidIdPart c then c else '_'
+ in case s of
+ "" -> "_"
+ (start:part) -> let fixed_id = (fixStart start):(map fixPart part)
+ in if isReservedWord fixed_id then '_':fixed_id
+ else fixed_id
-- | Fixes an incorrect nesting of break/continue, making the program
-- abide by the ECMAScript spec (page 92): any continue without a