Skip to content

Commit

Permalink
feat(es/ast): Add raw to Str (#4071)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 22, 2022
1 parent 5b6b9c0 commit 634d732
Show file tree
Hide file tree
Showing 3,442 changed files with 32,585 additions and 148,213 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 4 additions & 3 deletions crates/node/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ impl swc_bundler::Hook for Hook {
span: Span,
module_record: &ModuleRecord,
) -> Result<Vec<KeyValueProp>, Error> {
let file_name = module_record.file_name.to_string();

Ok(vec![
KeyValueProp {
key: PropName::Ident(Ident::new(js_word!("url"), span)),
value: Box::new(Expr::Lit(Lit::Str(Str {
span,
value: module_record.file_name.to_string().into(),
has_escape: false,
kind: Default::default(),
raw: None,
value: file_name.into(),
}))),
},
KeyValueProp {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
"\"";
'"';
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if (true) {
console.log('Pass');
console.log("Pass");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
console.log(true);
if (true) {
console.log('Pass');
console.log("Pass");
}
console.log('foo');
console.log("foo");
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as swcHelpers from "@swc/helpers";
var window = 'foo';
var window = "foo";
console.log(typeof window === "undefined" ? "undefined" : swcHelpers.typeOf(window));
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/hygiene/issue-3213/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function f() {
var value$22 = 'original string';
var value$22 = "original string";
if (true) {
var value$21 = 'new string';
var value$21 = "new string";
console.log(value$22);
}
[].map(function x(_) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
"use strict";
function print() {
var value$43 = 2;
var value$41 = value$43 + 100;
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issue-1107/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as swcHelpers from "@swc/helpers";
export var Class1 = function Class1(param) {
"use strict";
var _name = param.name, name = _name === void 0 ? '' : _name;
var _name = param.name, name = _name === void 0 ? "" : _name;
swcHelpers.classCallCheck(this, Class1);
console.log(name);
};
export var Class2 = function Class2(param) {
"use strict";
var _name = param.name, name = _name === void 0 ? '' : _name;
var _name = param.name, name = _name === void 0 ? "" : _name;
swcHelpers.classCallCheck(this, Class2);
console.log(name);
};
6 changes: 3 additions & 3 deletions crates/swc/tests/fixture/issue-1216/case-1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as swcHelpers from "@swc/helpers";
import regeneratorRuntime from "regenerator-runtime";
var source = Math.random() < 2 ? 'matilda' : 'fred';
var source = Math.random() < 2 ? "matilda" : "fred";
var details = {
_id: '1'
_id: "1"
};
function request(path) {
return _request.apply(this, arguments);
Expand All @@ -26,7 +26,7 @@ swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
if (!(source === 'matilda')) {
if (!(source === "matilda")) {
_ctx.next = 4;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/swc/tests/fixture/issue-1216/case-2/output/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as swcHelpers from "@swc/helpers";
import regeneratorRuntime from "regenerator-runtime";
var source = Math.random() < 2 ? 'matilda' : 'fred';
var source = Math.random() < 2 ? "matilda" : "fred";
var details = {
_id: '1'
_id: "1"
};
function request(path) {
return _request.apply(this, arguments);
Expand All @@ -26,7 +26,7 @@ swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
if (!(source === 'matilda')) {
if (!(source === "matilda")) {
_ctx.next = 4;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issue-1232/esm/output/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as action from './actions';
import { foo } from './actions';
import * as action from "./actions";
import { foo } from "./actions";
console.log(action);
console.log(foo);
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-1345/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as swcHelpers from "@swc/helpers";
var _class, _descriptor, _dec, _dec1, _descriptor1, _dec2, _dec3, _descriptor2, _dec4, _dec5, _descriptor3, _dec6, _dec7, _descriptor4, _dec8, _dec9, _descriptor5, _dec10, _dec11, _descriptor6, _dec12, _dec13, _descriptor7, _dec14, _dec15;
var _dec16 = ViewEntity({
name: "AccountMemberView",
expression: "\n SELECT\n m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick=\"F\") as accountCnt,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick=\"T\") as accountQuickCnt\n FROM TBLMEMBER m\n "
expression: '\n SELECT\n m.tmcode, m.mid, m.accea, m.qaccea, m.endday, m.quick_endday,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="F") as accountCnt,\n (SELECT COUNT(*) FROM TBLACCOUNT a WHERE m.mid = a.mid AND a.use_quick="T") as accountQuickCnt\n FROM TBLMEMBER m\n '
});
export var AccountMemberView = _class = _dec16((_class = function AccountMemberView() {
"use strict";
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issue-1421/case1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
var swcHelpers = require("@swc/helpers");
require("reflect-metadata");
var _class, _descriptor, _dec, _dec1;
var COL_KEY = Symbol('col');
var COL_KEY = Symbol("col");
var column = function() {
return function(object, key) {
Reflect.defineMetadata(COL_KEY, 'value', object, key);
Reflect.defineMetadata(COL_KEY, "value", object, key);
};
};
var User = ((_class = function User() {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-1455/case2/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ var obj = {
};
}()
};
obj.byPlatform('foo').then(function(v) {
obj.byPlatform("foo").then(function(v) {
return console.log(v);
});
10 changes: 5 additions & 5 deletions crates/swc/tests/fixture/issue-1457/case1/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { setGlobalOptions } from '@typegoose/typegoose';
import * as typegoose from '@typegoose/typegoose';
import { schemas } from './schemas';
import { setGlobalOptions } from "@typegoose/typegoose";
import * as typegoose from "@typegoose/typegoose";
import { schemas } from "./schemas";
// typegoose.mongoose.set('debug', true);
setGlobalOptions({
options: {
allowMixed: typegoose.Severity.ALLOW
},
schemaOptions: {
timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
createdAt: "created_at",
updatedAt: "updated_at"
}
}
});
Expand Down
10 changes: 5 additions & 5 deletions crates/swc/tests/fixture/issue-1457/case8-es5/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { setGlobalOptions } from '@typegoose/typegoose';
import * as typegoose from '@typegoose/typegoose';
import { schemas } from './schemas';
import { setGlobalOptions } from "@typegoose/typegoose";
import * as typegoose from "@typegoose/typegoose";
import { schemas } from "./schemas";
// typegoose.mongoose.set('debug', true);
setGlobalOptions({
options: {
allowMixed: typegoose.Severity.ALLOW
},
schemaOptions: {
timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
createdAt: "created_at",
updatedAt: "updated_at"
}
}
});
Expand Down
10 changes: 5 additions & 5 deletions crates/swc/tests/fixture/issue-1457/case9-es3/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { setGlobalOptions } from '@typegoose/typegoose';
import * as typegoose from '@typegoose/typegoose';
import { schemas } from './schemas';
import { setGlobalOptions } from "@typegoose/typegoose";
import * as typegoose from "@typegoose/typegoose";
import { schemas } from "./schemas";
// typegoose.mongoose.set('debug', true);
setGlobalOptions({
options: {
allowMixed: typegoose.Severity.ALLOW
},
schemaOptions: {
timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
createdAt: "created_at",
updatedAt: "updated_at"
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-1545/case1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { createHash, createHmac } from 'crypto-browserify';
import { createHash, createHmac } from "crypto-browserify";
var hash = createHash(algorithm);
var hmac = createHmac(fn, key);
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issue-1575/case1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as swcHelpers from "@swc/helpers";
import regeneratorRuntime from "regenerator-runtime";
Vue.component('test', {
Vue.component("test", {
methods: {
onSend: function onSend() {
return swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
if (this.msg === '') {}
if (this.msg === "") {}
case 1:
case "end":
return _ctx.stop();
Expand Down
12 changes: 6 additions & 6 deletions crates/swc/tests/fixture/issue-1687/output/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.promise.js";
import regeneratorRuntime from "regenerator-runtime";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { render } from 'react-dom';
import zhCN from 'antd/es/locale/zh_CN';
import { Button, ConfigProvider } from 'antd';
import { useEffect, useState } from "react";
import { render } from "react-dom";
import zhCN from "antd/es/locale/zh_CN";
import { Button, ConfigProvider } from "antd";
function App() {
var ref = swcHelpers.slicedToArray(useState({}), 2), state = ref[0], setState = ref[1];
useEffect(function() {
Expand All @@ -16,7 +16,7 @@ function App() {
case 0:
_ctx.t0 = setState;
_ctx.next = 3;
return fetch('/api/user');
return fetch("/api/user");
case 3:
_ctx.t1 = _ctx.sent;
(0, _ctx.t0)(_ctx.t1);
Expand All @@ -38,4 +38,4 @@ function App() {
]
});
}
render(/*#__PURE__*/ _jsx(App, {}), document.getElementById('root'));
render(/*#__PURE__*/ _jsx(App, {}), document.getElementById("root"));
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-1718/case1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _scanUser() {
break;
}
user = _step.value;
console.log('user', user);
console.log("user", user);
_ctx.next = 9;
return new Promise(function(resolve) {
return setTimeout(resolve, 30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var _class;
var TestClass = _class = someClassDecorator((_class = (_TestClass = function TestClass() {
"use strict";
swcHelpers.classCallCheck(this, TestClass);
}, _TestClass.Something = 'hello', _TestClass.SomeProperties = {
}, _TestClass.Something = "hello", _TestClass.SomeProperties = {
firstProp: _TestClass.Something
}, _TestClass)) || _class) || _class;
function someClassDecorator(c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee1() {
_ctx.next = 28;
break;
}
throw new Error('');
throw new Error("");
case 28:
case "end":
return _ctx.stop();
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-1918/es5/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ swcHelpers.asyncToGenerator(_regeneratorRuntime.default.mark(function _callee1()
_ctx.next = 28;
break;
}
throw new Error('');
throw new Error("");
case 28:
case "end":
return _ctx.stop();
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-1938/esm/output/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import foo, * as action from './actions';
import foo, * as action from "./actions";
console.log(action);
console.log(foo);
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-2022/no-opt/output/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function example() {
var a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'click', b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, c = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
var a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "click", b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, c = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
console.log(a, b, c);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-2024/full/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ swcHelpers.asyncToGenerator(_regeneratorRuntime.default.mark(function _callee()
_ctx.next = 6;
break;
}
_ctx.t0 = 'fallback';
_ctx.t0 = "fallback";
case 6:
result = _ctx.t0;
console.log(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
_ctx.next = 6;
break;
}
_ctx.t0 = 'fallback';
_ctx.t0 = "fallback";
case 6:
result = _ctx.t0;
console.log(result);
Expand Down

1 comment on commit 634d732

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 634d732 Previous: 4a9817f Ratio
base_tr_fixer 24348 ns/iter (± 2855) 29371 ns/iter (± 5243) 0.83
base_tr_resolver_and_hygiene 109153 ns/iter (± 31611) 124374 ns/iter (± 49258) 0.88
codegen_es2015 32698 ns/iter (± 3369) 34621 ns/iter (± 8375) 0.94
codegen_es2016 32852 ns/iter (± 5160) 33598 ns/iter (± 6706) 0.98
codegen_es2017 32802 ns/iter (± 2812) 34155 ns/iter (± 5751) 0.96
codegen_es2018 30167 ns/iter (± 5077) 37596 ns/iter (± 5540) 0.80
codegen_es2019 29821 ns/iter (± 3813) 35033 ns/iter (± 9787) 0.85
codegen_es2020 31244 ns/iter (± 4803) 35291 ns/iter (± 6783) 0.89
codegen_es3 31712 ns/iter (± 4003) 35132 ns/iter (± 7059) 0.90
codegen_es5 33457 ns/iter (± 2273) 34184 ns/iter (± 5664) 0.98
full_es2015 153722520 ns/iter (± 12359693) 157276900 ns/iter (± 17283620) 0.98
full_es2016 148550262 ns/iter (± 23247087) 157640244 ns/iter (± 19940263) 0.94
full_es2017 149155771 ns/iter (± 13839297) 153929280 ns/iter (± 12311870) 0.97
full_es2018 147206268 ns/iter (± 20845953) 155299187 ns/iter (± 18681497) 0.95
full_es2019 147326095 ns/iter (± 17068798) 151126242 ns/iter (± 15232746) 0.97
full_es2020 140878203 ns/iter (± 12211253) 152166344 ns/iter (± 13712793) 0.93
full_es3 199883806 ns/iter (± 15124942) 207897779 ns/iter (± 21634073) 0.96
full_es5 185893066 ns/iter (± 14859935) 194914716 ns/iter (± 18038099) 0.95
parser 592793 ns/iter (± 58040) 696900 ns/iter (± 113757) 0.85
ser_ast_node 162 ns/iter (± 15) 176 ns/iter (± 41) 0.92
ser_serde 155 ns/iter (± 13) 167 ns/iter (± 29) 0.93
emit_colors 11020158 ns/iter (± 7039366) 11552262 ns/iter (± 6740165) 0.95
emit_large 53222637 ns/iter (± 79054125) 50517009 ns/iter (± 73132246) 1.05
base_clone 2595133 ns/iter (± 277844) 2581568 ns/iter (± 499415) 1.01
fold_span 4260726 ns/iter (± 460319) 4395002 ns/iter (± 819072) 0.97
fold_span_panic 4014529 ns/iter (± 337507) 4720339 ns/iter (± 827507) 0.85
visit_mut_span 2844217 ns/iter (± 278989) 3088948 ns/iter (± 598359) 0.92
visit_mut_span_panic 2941650 ns/iter (± 274343) 3216821 ns/iter (± 709137) 0.91
usage_builtin_type 16765592 ns/iter (± 11641889) 17878267 ns/iter (± 12118300) 0.94
usage_property 442095 ns/iter (± 56315) 452125 ns/iter (± 99634) 0.98
boxing_boxed 177 ns/iter (± 4) 152 ns/iter (± 27) 1.16
boxing_boxed_clone 84 ns/iter (± 5) 77 ns/iter (± 15) 1.09
boxing_unboxed 145 ns/iter (± 5) 131 ns/iter (± 30) 1.11
boxing_unboxed_clone 66 ns/iter (± 8) 73 ns/iter (± 18) 0.90
time_10 380 ns/iter (± 50) 319 ns/iter (± 72) 1.19
time_15 739 ns/iter (± 80) 751 ns/iter (± 214) 0.98
time_20 1432 ns/iter (± 212) 1370 ns/iter (± 316) 1.05
time_40 4458 ns/iter (± 643) 4746 ns/iter (± 1105) 0.94
time_5 119 ns/iter (± 14) 112 ns/iter (± 36) 1.06
time_60 10300 ns/iter (± 1442) 10266 ns/iter (± 2537) 1.00
total 0 ns/iter (± 0) 0 ns/iter (± 0) NaN

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.