Repository: swc-project/swc (rust)

Issue:
transpiler: es3 needs brackets for __proto__ ?
i'm surprised that

```
function test(a, b){a.__proto__=b}
```
is transpiled to
```
function test(a,b){a["__proto__"]=b}
```
using
```
{
	"sourceMaps": false,
	"jsc": {
		"loose": true,
		"parser": {
			"syntax": "ecmascript"
		},
		"target": "es3",
		"minify": {
			"compress": true,
			"mangle": true
		}
	},
	"minify": true
}
```


Pull request description:
fix(es/utils): Fix `is_valid_ident`
swc_ecma_utils:
 - Fix `is_valid_ident`. (Closes #2118)

Patch:
diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs
index 20ba3d512f..9b90c2bf69 100644
--- a/crates/swc_ecma_utils/src/lib.rs
+++ b/crates/swc_ecma_utils/src/lib.rs
@@ -1861,8 +1861,8 @@ pub fn is_valid_ident(s: &JsWord) -> bool {
     if s.len() == 0 {
         return false;
     }
-    let first = s.chars().next().unwrap();
-    UnicodeXID::is_xid_start(first) && s.chars().skip(1).all(UnicodeXID::is_xid_continue)
+
+    Ident::verify_symbol(&s).is_ok()
 }
 
 pub fn drop_span<T>(mut t: T) -> T


Test patch:
diff --git a/crates/swc/tests/fixture/iissue-2118/input/.swcrc b/crates/swc/tests/fixture/iissue-2118/input/.swcrc
new file mode 100644
index 0000000000..28be1dfd6d
--- /dev/null
+++ b/crates/swc/tests/fixture/iissue-2118/input/.swcrc
@@ -0,0 +1,15 @@
+{
+    "sourceMaps": false,
+    "jsc": {
+        "loose": true,
+        "parser": {
+            "syntax": "ecmascript"
+        },
+        "target": "es3",
+        "minify": {
+            "compress": true,
+            "mangle": true
+        }
+    },
+    "minify": true
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/iissue-2118/input/index.js b/crates/swc/tests/fixture/iissue-2118/input/index.js
new file mode 100644
index 0000000000..b3010c47b4
--- /dev/null
+++ b/crates/swc/tests/fixture/iissue-2118/input/index.js
@@ -0,0 +1,3 @@
+function test(a, b) {
+    a.__proto__ = b
+}
diff --git a/crates/swc/tests/fixture/iissue-2118/output/index.js b/crates/swc/tests/fixture/iissue-2118/output/index.js
new file mode 100644
index 0000000000..f83c952183
--- /dev/null
+++ b/crates/swc/tests/fixture/iissue-2118/output/index.js
@@ -0,0 +1,1 @@
+function test(a,b){a.__proto__=b}
diff --git a/crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-determanated-instance-methods/output.mjs b/crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-determanated-instance-methods/output.mjs
index d69116ed87..ac5ab1ae48 100644
--- a/crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-determanated-instance-methods/output.mjs
+++ b/crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-determanated-instance-methods/output.mjs
@@ -16,7 +16,7 @@ a.values();
 ''.includes();
 /./gi.flags;
 ''.indexOf();
-a["__defineGetter__"]('foo', function() {
+a.__defineGetter__('foo', function() {
     return 42;
 });
 a.trim;