@rspack/test-tools 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/case/diff.js CHANGED
@@ -76,7 +76,7 @@ function createDiffCase(name, src, dist) {
76
76
  }
77
77
  exports.createDiffCase = createDiffCase;
78
78
  function createDiffProcessor(config) {
79
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
79
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
80
80
  const fileCompareMap = new Map();
81
81
  const createCompareResultHandler = (type) => {
82
82
  return (file, results) => {
@@ -98,13 +98,14 @@ function createDiffProcessor(config) {
98
98
  ignoreModuleArguments: (_b = config.ignoreModuleArguments) !== null && _b !== void 0 ? _b : true,
99
99
  ignorePropertyQuotationMark: (_c = config.ignorePropertyQuotationMark) !== null && _c !== void 0 ? _c : true,
100
100
  ignoreBlockOnlyStatement: (_d = config.ignoreBlockOnlyStatement) !== null && _d !== void 0 ? _d : true,
101
- ignoreSwcHelpersPath: (_e = config.ignoreSwcHelpersPath) !== null && _e !== void 0 ? _e : true,
102
- ignoreObjectPropertySequence: (_f = config.ignoreObjectPropertySequence) !== null && _f !== void 0 ? _f : true,
103
- ignoreCssFilePath: (_g = config.ignoreCssFilePath) !== null && _g !== void 0 ? _g : true,
101
+ ignoreIfCertainCondition: (_e = config.ignoreIfCertainCondition) !== null && _e !== void 0 ? _e : true,
102
+ ignoreSwcHelpersPath: (_f = config.ignoreSwcHelpersPath) !== null && _f !== void 0 ? _f : true,
103
+ ignoreObjectPropertySequence: (_g = config.ignoreObjectPropertySequence) !== null && _g !== void 0 ? _g : true,
104
+ ignoreCssFilePath: (_h = config.ignoreCssFilePath) !== null && _h !== void 0 ? _h : true,
104
105
  onCompareModules: createCompareResultHandler("modules"),
105
106
  onCompareRuntimeModules: createCompareResultHandler("runtimeModules"),
106
- bootstrap: (_h = config.bootstrap) !== null && _h !== void 0 ? _h : true,
107
- detail: (_j = config.detail) !== null && _j !== void 0 ? _j : true
107
+ bootstrap: (_j = config.bootstrap) !== null && _j !== void 0 ? _j : true,
108
+ detail: (_k = config.detail) !== null && _k !== void 0 ? _k : true
108
109
  });
109
110
  return [processor, fileCompareMap];
110
111
  }
@@ -24,6 +24,7 @@ class DiffComparator {
24
24
  ignoreModuleId: true,
25
25
  ignoreModuleArguments: true,
26
26
  ignoreBlockOnlyStatement: true,
27
+ ignoreIfCertainCondition: true,
27
28
  ignoreSwcHelpersPath: true,
28
29
  ignoreObjectPropertySequence: true,
29
30
  ignoreCssFilePath: true
@@ -7,5 +7,6 @@ export interface IFormatCodeOptions {
7
7
  ignoreSwcHelpersPath: boolean;
8
8
  ignoreObjectPropertySequence: boolean;
9
9
  ignoreCssFilePath: boolean;
10
+ ignoreIfCertainCondition: boolean;
10
11
  }
11
12
  export declare function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;
@@ -40,6 +40,13 @@ function formatCode(name, raw, options) {
40
40
  sourceType: "unambiguous"
41
41
  });
42
42
  (0, traverse_1.default)(ast, {
43
+ BlockStatement(path) {
44
+ if (options.ignoreBlockOnlyStatement) {
45
+ if (path.parentPath.isBlockStatement()) {
46
+ path.replaceWithMultiple(path.node.body);
47
+ }
48
+ }
49
+ },
43
50
  ObjectProperty(path) {
44
51
  if (options.ignorePropertyQuotationMark) {
45
52
  const keyPath = path.get("key");
@@ -64,20 +71,69 @@ function formatCode(name, raw, options) {
64
71
  }
65
72
  }
66
73
  },
74
+ StringLiteral(path) {
75
+ var _a;
76
+ if ((_a = path.node.extra) === null || _a === void 0 ? void 0 : _a.raw) {
77
+ path.node.extra.raw = JSON.stringify(path.node.extra.rawValue);
78
+ }
79
+ },
67
80
  IfStatement(path) {
81
+ let consequentNode;
82
+ let alternateNode;
68
83
  if (options.ignoreBlockOnlyStatement) {
69
84
  const consequent = path.get("consequent");
70
85
  if (consequent.isBlockStatement() &&
71
86
  consequent.node.body.length === 1) {
72
87
  consequent.node.body[0].leadingComments =
73
88
  consequent.node.leadingComments;
74
- consequent.replaceWith(T.cloneNode(consequent.node.body[0], true, false));
89
+ consequentNode = consequent.node.body[0];
90
+ consequent.replaceWith(consequentNode);
75
91
  }
76
92
  const alternate = path.get("alternate");
77
93
  if (alternate.isBlockStatement() && alternate.node.body.length === 1) {
78
94
  alternate.node.body[0].leadingComments =
79
95
  alternate.node.leadingComments;
80
- alternate.replaceWith(T.cloneNode(alternate.node.body[0], true, false));
96
+ alternateNode = alternate.node.body[0];
97
+ alternate.replaceWith(alternateNode);
98
+ }
99
+ }
100
+ if (options.ignoreIfCertainCondition) {
101
+ const testExpr = path.get("test");
102
+ const testResult = testExpr.isBooleanLiteral()
103
+ ? testExpr.node.value
104
+ : undefined;
105
+ if (typeof testResult === "boolean") {
106
+ if (testResult) {
107
+ const consequent = path.get("consequent");
108
+ if (consequent.isBlockStatement()) {
109
+ if (consequentNode) {
110
+ path.replaceWith(consequentNode);
111
+ }
112
+ else {
113
+ path.replaceWithMultiple(consequent.node.body);
114
+ }
115
+ }
116
+ else {
117
+ path.replaceWith(consequent);
118
+ }
119
+ }
120
+ else {
121
+ const alternate = path.get("alternate");
122
+ if (alternate.isBlockStatement()) {
123
+ if (alternateNode) {
124
+ path.replaceWith(alternateNode);
125
+ }
126
+ else {
127
+ path.replaceWithMultiple(alternate.node.body);
128
+ }
129
+ }
130
+ else if (alternate.isStatement()) {
131
+ path.replaceWith(alternate);
132
+ }
133
+ else {
134
+ path.remove();
135
+ }
136
+ }
81
137
  }
82
138
  }
83
139
  },
@@ -90,6 +146,15 @@ function formatCode(name, raw, options) {
90
146
  }
91
147
  }
92
148
  },
149
+ While(path) {
150
+ if (options.ignoreBlockOnlyStatement) {
151
+ const body = path.get("body");
152
+ if (body.isBlockStatement() && body.node.body.length === 1) {
153
+ body.node.body[0].leadingComments = body.node.leadingComments;
154
+ body.replaceWith(T.cloneNode(body.node.body[0], true, false));
155
+ }
156
+ }
157
+ },
93
158
  SwitchCase(path) {
94
159
  if (path.node.consequent.length === 1 &&
95
160
  path.node.consequent[0].type === "BlockStatement") {
@@ -88,6 +88,7 @@ class DiffProcessor {
88
88
  ignoreModuleId: this.options.ignoreModuleId,
89
89
  ignorePropertyQuotationMark: this.options.ignorePropertyQuotationMark,
90
90
  ignoreBlockOnlyStatement: this.options.ignoreBlockOnlyStatement,
91
+ ignoreIfCertainCondition: this.options.ignoreIfCertainCondition,
91
92
  ignoreSwcHelpersPath: this.options.ignoreSwcHelpersPath,
92
93
  ignoreObjectPropertySequence: this.options.ignoreObjectPropertySequence,
93
94
  ignoreCssFilePath: this.options.ignoreCssFilePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -41,7 +41,7 @@
41
41
  "webpack": "^5.90.0",
42
42
  "webpack-sources": "3.2.3",
43
43
  "which-module": "2.0.1",
44
- "@rspack/core": "0.5.4"
44
+ "@rspack/core": "0.5.5"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@arco-design/web-react": "^2.56.1",
@@ -52,17 +52,16 @@
52
52
  "@types/react-dom": "^18.2.18",
53
53
  "@types/webpack": "5.28.5",
54
54
  "@types/webpack-sources": "3.2.3",
55
- "core-js": "3.35.1",
55
+ "core-js": "3.36.0",
56
56
  "jest-serializer-path": "^0.1.15",
57
- "monaco-editor": "0.45.0",
57
+ "monaco-editor": "0.46.0",
58
58
  "monaco-editor-webpack-plugin": "7.1.0",
59
59
  "normalize.css": "^8.0.0",
60
60
  "react": "18.0.0",
61
61
  "react-dom": "18.0.0",
62
62
  "react-refresh": "0.14.0",
63
- "@rspack/cli": "0.5.4"
63
+ "@rspack/cli": "0.5.5"
64
64
  },
65
- "peerDependenciesMeta": {},
66
65
  "scripts": {
67
66
  "build": "tsc -b ./tsconfig.build.json",
68
67
  "build:viewer": "rspack build",