From 84b615df3dc4fe61d00c62338909ca8b163eb16a Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Mon, 7 Aug 2017 13:12:58 -0700 Subject: [PATCH] Scrub all non-identifier characters from JavaScript class names Class names from kernel contain "&", "#", "^" etc BUG= R=efortuna@google.com Review-Url: https://codereview.chromium.org/2999473002 . --- pkg/compiler/lib/src/js_backend/namer.dart | 4 +- .../dart2js_extra/dart2js_extra.status | 1 - tests/language/language_dart2js.status | 58 +------------------ 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart index 52eaa5591b4..a5b21318606 100644 --- a/pkg/compiler/lib/src/js_backend/namer.dart +++ b/pkg/compiler/lib/src/js_backend/namer.dart @@ -1286,9 +1286,11 @@ class Namer { /// Returns a proposed name for the given typedef or class [element]. /// The returned id is guaranteed to be a valid JavaScript identifier. String _proposeNameForType(Entity element) { - return element.name.replaceAll('+', '_'); + return element.name.replaceAll(_nonIdentifierRE, '_'); } + static RegExp _nonIdentifierRE = new RegExp(r'[^A-Za-z0-9_$]'); + /// Returns a proposed name for the given top-level or static member /// [element]. The returned id is guaranteed to be a valid JavaScript /// identifier. diff --git a/tests/compiler/dart2js_extra/dart2js_extra.status b/tests/compiler/dart2js_extra/dart2js_extra.status index 153a83f2256..abcd70474f9 100644 --- a/tests/compiler/dart2js_extra/dart2js_extra.status +++ b/tests/compiler/dart2js_extra/dart2js_extra.status @@ -183,7 +183,6 @@ regress/4562_test/01: Crash # Issue 27394 22776_test: Crash 22868_test: Crash 22917_test: Crash -23056_test: RuntimeError 23264_test: Crash 23404_test: Crash 23432_test: Crash diff --git a/tests/language/language_dart2js.status b/tests/language/language_dart2js.status index 7c6853a063a..deea96c6a9e 100644 --- a/tests/language/language_dart2js.status +++ b/tests/language/language_dart2js.status @@ -1034,7 +1034,6 @@ generic_function_typedef2_test/04: Crash generic_function_typedef2_test/none: Crash generic_function_typedef_test: Crash generic_functions_test: Crash -generic_instanceof5_test: Crash generic_instanceof_test: Crash generic_list_checked_test: Crash generic_local_functions_test: Crash @@ -1238,7 +1237,6 @@ issue_22780_test/01: Crash issue_23914_test: Crash issue_25671a_test/01: Crash issue_25671b_test/01: Crash -issue_25671b_test/none: Crash label_test: Crash lazy_map_test: Crash lazy_static3_test: Crash @@ -1322,7 +1320,6 @@ malbounded_type_cast_test: Crash malbounded_type_literal_test: Crash malbounded_type_test2_test: Crash malformed2_test/00: Crash -malformed_inheritance_test/04: Crash malformed_test/01: Crash malformed_test/02: Crash malformed_test/03: Crash @@ -1367,9 +1364,7 @@ mint_compares_test: Crash missing_const_constructor_test/01: Crash missing_const_constructor_test/none: Crash mixin_black_listed_test/02: Crash -mixin_black_listed_test/none: Crash mixin_bound_test: Crash -mixin_class_from_core_library_test: Crash mixin_extends_field_test: Crash mixin_extends_is_test: Crash mixin_extends_method_test: Crash @@ -1379,21 +1374,13 @@ mixin_forwarding_constructor1_test: Crash mixin_forwarding_constructor2_test: Crash mixin_forwarding_constructor3_test: Crash mixin_forwarding_constructor4_test/01: Crash +mixin_forwarding_constructor4_test/01: MissingCompileTimeError mixin_forwarding_constructor4_test/02: Crash +mixin_forwarding_constructor4_test/02: MissingCompileTimeError mixin_forwarding_constructor4_test/03: Crash -mixin_forwarding_constructor4_test/none: Crash +mixin_forwarding_constructor4_test/03: MissingCompileTimeError mixin_generic_test: Crash mixin_getter_regression_test: Crash -generic_instanceof5_test: RuntimeError -issue_25671b_test/none: RuntimeError -malformed_inheritance_test/04: RuntimeError -mixin_black_listed_test/none: RuntimeError -mixin_class_from_core_library_test: RuntimeError -mixin_forwarding_constructor4_test/01: MissingCompileTimeError -mixin_forwarding_constructor4_test/02: MissingCompileTimeError -mixin_forwarding_constructor4_test/03: MissingCompileTimeError -mixin_forwarding_constructor4_test/none: RuntimeError -mixin_illegal_constructor_test/none: RuntimeError mixin_illegal_static_access_test: Crash mixin_illegal_super_use_test/01: Crash mixin_illegal_super_use_test/02: Crash @@ -1437,34 +1424,7 @@ mixin_illegal_superclass_test/27: MissingCompileTimeError mixin_illegal_superclass_test/28: Crash mixin_illegal_superclass_test/29: MissingCompileTimeError mixin_illegal_superclass_test/30: Crash -mixin_illegal_superclass_test/none: RuntimeError -mixin_illegal_syntax_test/none: RuntimeError mixin_implements_test: Crash -mixin_invalid_bound2_test/01: RuntimeError -mixin_invalid_bound2_test/02: RuntimeError -mixin_invalid_bound2_test/03: RuntimeError -mixin_invalid_bound2_test/04: RuntimeError -mixin_invalid_bound2_test/05: RuntimeError -mixin_invalid_bound2_test/06: RuntimeError -mixin_invalid_bound2_test/07: RuntimeError -mixin_invalid_bound2_test/08: RuntimeError -mixin_invalid_bound2_test/09: RuntimeError -mixin_invalid_bound2_test/10: RuntimeError -mixin_invalid_bound2_test/11: RuntimeError -mixin_invalid_bound2_test/12: RuntimeError -mixin_invalid_bound2_test/13: RuntimeError -mixin_invalid_bound2_test/14: RuntimeError -mixin_invalid_bound_test/01: RuntimeError -mixin_invalid_bound_test/02: RuntimeError -mixin_invalid_bound_test/03: RuntimeError -mixin_invalid_bound_test/04: RuntimeError -mixin_invalid_bound_test/05: RuntimeError -mixin_invalid_bound_test/06: RuntimeError -mixin_invalid_bound_test/07: RuntimeError -mixin_invalid_bound_test/08: RuntimeError -mixin_invalid_bound_test/09: RuntimeError -mixin_invalid_bound_test/10: RuntimeError -mixin_is_test: RuntimeError mixin_issue10216_2_test: Crash mixin_issue10216_test: Crash mixin_lib_extends_field_test: Crash @@ -1550,18 +1510,10 @@ mixin_supertype_subclass_test/04: CompileTimeError mixin_supertype_subclass_test/05: CompileTimeError mixin_supertype_subclass_test/none: CompileTimeError mixin_this_use_test: Crash -mixin_type_parameter1_test: RuntimeError -mixin_type_parameter2_test: RuntimeError mixin_type_parameter3_test: Crash mixin_type_parameter4_test: Crash mixin_type_parameter5_test: Crash mixin_type_parameter6_test: Crash -mixin_type_parameters_errors_test/01: RuntimeError -mixin_type_parameters_errors_test/02: RuntimeError -mixin_type_parameters_errors_test/03: RuntimeError -mixin_type_parameters_errors_test/04: RuntimeError -mixin_type_parameters_errors_test/05: RuntimeError -mixin_type_parameters_errors_test/none: RuntimeError mixin_type_parameters_mixin_extends_test: Crash mixin_type_parameters_mixin_test: Crash mixin_type_parameters_simple_test: Crash @@ -1755,7 +1707,6 @@ regress_18435_test: Crash regress_18535_test: Crash regress_18713_test: Crash regress_20394_test/01: Crash -regress_20394_test/none: RuntimeError regress_20840_test: Crash regress_21016_test: Crash regress_21795_test: Crash @@ -1877,7 +1828,6 @@ super_field_access_test: Crash super_getter_setter_test: Crash super_implicit_closure_test: Crash super_inferrer_test: Crash -super_mixin_test: RuntimeError super_no_such_method1_test/01: Crash super_no_such_method2_test/01: Crash super_no_such_method3_test/01: Crash @@ -2050,9 +2000,7 @@ type_variable_typedef_test: Crash typecheck_multifield_declaration_test: Crash typedef_is_test: Crash typedef_uses_test: Crash # type 'FunctionType' is not a subtype of type 'ResolutionFunctionType' of 'type' where -typevariable_substitution2_test/01: RuntimeError typevariable_substitution2_test/02: Crash -typevariable_substitution2_test/none: RuntimeError unresolved_default_constructor_test/01: Crash value_range2_test: Crash value_range3_test: Crash