Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es): Fix default value of jsc.minify.format.comments #7853

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl Options {
.as_ref()
.map(|v| match v.format.comments.clone().into_inner() {
Some(v) => v,
None => BoolOr::Bool(false),
None => BoolOr::Bool(true),
})
.unwrap_or_else(|| {
BoolOr::Data(if cfg.minify.into_bool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function f() {
console.log(value$2);
}
[].map(function x(_) {
var value$2;
var value$2; // this causes the previous value$2 to become value$21
return value$2;
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var n;
module.exports = ((n = function() {
module.exports = ((n = /*#__PURE__*/ function() {
function n() {}
return n.prototype.it = function() {
this.bb = new n.MyA();
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-2xxx/2854/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export function App() {
return React.createElement(Form, null);
return /*#__PURE__*/ React.createElement(Form, null);
}
export function Form(param) {
var _param_onChange = param.onChange, onChange = _param_onChange === void 0 ? function() {} : _param_onChange;
return React.createElement("input", {
return /*#__PURE__*/ React.createElement("input", {
onChange: function onChange1() {
onChange();
}
Expand Down
3 changes: 2 additions & 1 deletion crates/swc/tests/fixture/issues-2xxx/2926/output/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export var webpackJsonpCallback = function(parentChunkLoadingFunction, data) {
var runtime = data[2];
/******/ var runtime = data[2];
runtime && runtime(__webpack_require__);
// return result
};
18 changes: 10 additions & 8 deletions crates/swc/tests/fixture/issues-3xxx/3126/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
var __webpack_exports__;
__webpack_require__.m = {
746: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__1) {
/******/ var __webpack_exports__;
/************************************************************************/ /******/ /******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = {
/***/ 746: /***/ function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__1) {
Object.prototype.hasOwnProperty;
}
}, __webpack_require__.O = function(result, chunkIds, fn, priority) {
for(var j = 0; j < chunkIds.length; j++)Object.keys(__webpack_require__.O).every(function(key) {
// END MY ACTUAL CODE
/***/ }
}, /******/ __webpack_require__.O = function(result, chunkIds, fn, priority) {
/******/ for(var j = 0; j < chunkIds.length; j++)/******/ Object.keys(__webpack_require__.O).every(function(key) {
return __webpack_require__.O[key](chunkIds[j]);
});
}, __webpack_exports__ = __webpack_require__.O(void 0, [
/******/ }, __webpack_exports__ = __webpack_require__.O(void 0, [
532
], function() {
return __webpack_require__(746);
}), __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
}), /******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ServiceError = _ts_decorate._([
Code[Code["badResponse"] = 422] = "badResponse";
})(Code = ServiceError1.Code || (ServiceError1.Code = {}));
class ServiceNotFound extends ServiceError {
// Service was probably not registered, or using the wrong channel
code = 404;
name = "ServiceError.ServiceNotFound";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// filename: types.d.ts
export const aThing;
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/issues-4xxx/4120/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// b becomes "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02B8\u0300-\u0590\u0900-\u1FFF\u200E\u2C00-\\\0ud801\\\0ud804-\\\0ud839\\\0ud83c-\\\0udbff\uF900-\uFB1C\uFE00-\uFE6F\uFEFD-\uFFFF"
// ref: both strings are contained in 'google-protobuf'.
export default{a:"֑-ۯۺ-ࣿ‏\ud802-\ud803\ud83a-\ud83bיִ-﷿ﹰ-ﻼ",b:"A-Za-z\xc0-\xd6\xd8-\xf6\xf8-ʸ̀-֐ऀ-῿‎Ⰰ-\ud801\ud804-\ud839\ud83c-\udbff豈-﬜︀-﹯﻽-￿"};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": "AAUA,cAAe,CAAEA,EATb,0CASgBC,EALhB,kFAKkB,CAAE",
"mappings": "AAMA,+KAA+K;AAE/K,wDAAwD;AAExD,cAAe,CAAEA,EATb,0CASgBC,EALhB,kFAKkB,CAAE",
"names": [
"a",
"b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export var CompanyBgStore = function CompanyBgStore() {
_class_call_check(this, CompanyBgStore);
_define_property(this, "corpName", 123);
var _this = this;
_define_property(this, "getBusinessInfo", _async_to_generator(function() {
_define_property(this, "getBusinessInfo", /*#__PURE__*/ _async_to_generator(function() {
var corpName;
var _arguments = arguments;
return _ts_generator(this, function(_state) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _ as _class_private_field_loose_base } from "@swc/helpers/_/_class_private_field_loose_base";
import { _ as _class_private_field_loose_key } from "@swc/helpers/_/_class_private_field_loose_key";
var _channelName = _class_private_field_loose_key("_channelName"), _listeners = _class_private_field_loose_key("_listeners");
var _channelName = /*#__PURE__*/ _class_private_field_loose_key("_channelName"), _listeners = /*#__PURE__*/ _class_private_field_loose_key("_listeners");
export class LocalStorageChannel {
constructor(channelName){
Object.defineProperty(this, _channelName, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define([
], function(require, _ts_decorate) {
"use strict";
function es5ClassCompat(target) {
///@ts-expect-error
function _() {
return Reflect.construct(target, arguments, this.constructor);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
/* eslint-disable */ "use strict";
function _default(e, t) {
"use strict";
t.vr = function(e, t, r) {
Expand Down
6 changes: 6 additions & 0 deletions crates/swc/tests/fixture/issues-5xxx/5258/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define([
}
});
function es5ClassCompat(target) {
///@ts-expect-error
function _() {
return Reflect.construct(target, arguments, this.constructor);
}
Expand Down Expand Up @@ -43,11 +44,16 @@ define([
super(URI.isUri(uriOrMessage) ? uriOrMessage.toString(true) : uriOrMessage);
_define_property._(this, "code", void 0);
this.code = terminator?.name ?? 'Unknown';
// mark the error as file system provider error so that
// we can extract the error code on the receiving side
markAsFileSystemProviderError(this, code);
// workaround when extending builtin objects and when compiling to ES5, see:
// https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
if (typeof Object.setPrototypeOf === 'function') {
Object.setPrototypeOf(this, FileSystemError.prototype);
}
if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') {
// nice stack traces
Error.captureStackTrace(this, terminator);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
var commands;
var command;
function retornaTempoArenaEmMilisegundos(distancia, velocidade) {
var conv = distancia * function() {
var conv = distancia * /*#__PURE__*/ function() {
"use strict";
function LogExit(param) {
var logger = param.logger;
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-5xxx/5558/2/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _create_class } from "@swc/helpers/_/_create_class";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
var Foo = function() {
var Foo = /*#__PURE__*/ function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
Expand All @@ -11,7 +11,7 @@ var Foo = function() {
{
key: "bar",
value: function bar() {
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _async_to_generator(function() {
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : /*#__PURE__*/ _async_to_generator(function() {
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Base {
return 'good';
}
}
var _privateMethod = new WeakSet();
var _privateMethod = /*#__PURE__*/ new WeakSet();
class Sub extends Base {
superMethod() {
return 'bad';
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-6xxx/6984/1/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { _ as _create_super } from "@swc/helpers/_/_create_super";
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
import React from "react";
import { withRouter } from "react-router-dom";
var App = function(_React_Component) {
var App = /*#__PURE__*/ function(_React_Component) {
"use strict";
_inherits(App, _React_Component);
var _super = _create_super(App);
Expand All @@ -18,7 +18,7 @@ var App = function(_React_Component) {
key: "render",
value: function render() {
console.log(this.props);
return React.createElement("div", null, "134");
return /*#__PURE__*/ React.createElement("div", null, "134");
}
}
]);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7700/output/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ let positions = {
};
export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? rtlPositions : positions)[position];
return React.createElement("h1", null, "PositionRender: ", display);
return /*#__PURE__*/ React.createElement("h1", null, "PositionRender: ", display);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7700/output/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export function PositionRender({ isRtl, position }) {
] : {
positions
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
return /*#__PURE__*/ React.createElement("h1", null, "PositionRender: ", display);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7700/output/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export function PositionRender({ isRtl, position }) {
] : {
positions
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
return /*#__PURE__*/ React.createElement("h1", null, "PositionRender: ", display);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7700/output/4.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? rtlPositions : {
a: positions
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
return /*#__PURE__*/ React.createElement("h1", null, "PositionRender: ", display);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7700/output/5.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export function PositionRender({ isRtl, position }) {
positions
]
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
return /*#__PURE__*/ React.createElement("h1", null, "PositionRender: ", display);
}
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7783/output/1.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function e(){return React.createElement("div",null,foo.a)}let foo={get a(){return`a ${this.b}`},get b(){return"b"}};
export default function e(){return /*#__PURE__*/React.createElement("div",null,foo.a)}let foo={get a(){return`a ${this.b}`},get b(){return"b"}};
7 changes: 4 additions & 3 deletions crates/swc/tests/fixture/issues-7xxx/7821/output/1.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var Blocks = {
Block1: function() {
return React.createElement(React.Fragment, null, "'Block1xx'");
return /*#__PURE__*/ React.createElement(React.Fragment, null, "'Block1xx'");
},
Block2: function() {
return React.createElement(React.Fragment, null, "'Block2xx'");
return /*#__PURE__*/ React.createElement(React.Fragment, null, "'Block2xx'");
},
Layout1: function() {
// In the final code, Blocks does not have a 'Block1' key
return [
"Block1"
].map(function(e) {
Expand All @@ -14,5 +15,5 @@ var Blocks = {
}
};
export function render() {
return React.createElement(Blocks.Layout1, null);
return /*#__PURE__*/ React.createElement(Blocks.Layout1, null);
}
18 changes: 18 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7842/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2022",
"minify": {
"mangle": false,
"compress": false
}
},
"minify": false,
"isModule": true,
"module": {
"type": "commonjs"
}
}
58 changes: 58 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7842/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';
function emptyFunction() { }
function emptyFunctionWithReset() { }
emptyFunctionWithReset.resetWarningCache = emptyFunction;

module.exports = function () {
function shim(props, propName, componentName, location, propFullName, secret) {
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use PropTypes.checkPropTypes() to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
err.name = 'Invariant Violation';
throw err;
};
shim.isRequired = shim;
function getShim() {
return shim;
};
// Important!
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
var ReactPropTypes = {
array: shim,
bigint: shim,
bool: shim,
func: shim,
number: shim,
object: shim,
string: shim,
symbol: shim,

any: shim,
arrayOf: getShim,
element: shim,
elementType: shim,
instanceOf: getShim,
node: shim,
objectOf: getShim,
oneOf: getShim,
oneOfType: getShim,
shape: getShim,
exact: getShim,

checkPropTypes: emptyFunctionWithReset,
resetWarningCache: emptyFunction
};

ReactPropTypes.PropTypes = ReactPropTypes;

return ReactPropTypes;
};
49 changes: 49 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7842/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/ 'use strict';
function emptyFunction() {}
function emptyFunctionWithReset() {}
emptyFunctionWithReset.resetWarningCache = emptyFunction;
module.exports = function() {
function shim(props, propName, componentName, location, propFullName, secret) {
var err = new Error('Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
err.name = 'Invariant Violation';
throw err;
}
;
shim.isRequired = shim;
function getShim() {
return shim;
}
;
// Important!
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
var ReactPropTypes = {
array: shim,
bigint: shim,
bool: shim,
func: shim,
number: shim,
object: shim,
string: shim,
symbol: shim,
any: shim,
arrayOf: getShim,
element: shim,
elementType: shim,
instanceOf: getShim,
node: shim,
objectOf: getShim,
oneOf: getShim,
oneOfType: getShim,
shape: getShim,
exact: getShim,
checkPropTypes: emptyFunctionWithReset,
resetWarningCache: emptyFunction
};
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/sourcemap/003/output/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading