Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix * fix jest * revert and add a test
- Loading branch information
1 parent
978ea31
commit 1c2311a
Showing
28 changed files
with
315 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,13 +174,19 @@ class Printer { | |
* Add a right brace to the buffer. | ||
*/ | ||
|
||
rightBrace(): void { | ||
rightBrace(node: t.Node): void { | ||
if (this.format.minified) { | ||
this._buf.removeLastSemicolon(); | ||
} | ||
this.sourceWithOffset("end", node.loc, 0, -1); | ||
this.token("}"); | ||
} | ||
|
||
rightParens(node: t.Node): void { | ||
this.sourceWithOffset("end", node.loc, 0, -1); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
liuxingbaoyu
Author
Member
|
||
this.token(")"); | ||
} | ||
|
||
/** | ||
* Add a space to the buffer unless it is compact. | ||
*/ | ||
|
@@ -240,7 +246,6 @@ class Printer { | |
/** | ||
* Writes a simple token. | ||
*/ | ||
|
||
token(str: string, maybeNewline = false): void { | ||
this._maybePrintInnerComments(); | ||
|
||
|
@@ -270,8 +275,6 @@ class Printer { | |
tokenChar(char: number): void { | ||
this._maybePrintInnerComments(); | ||
|
||
// space is mandatory to avoid outputting <!-- | ||
// http://javascript.spec.whatwg.org/#comment-syntax | ||
const lastChar = this.getLastChar(); | ||
if ( | ||
// Need spaces for operators of the same kind to avoid: `a+++b` | ||
|
@@ -553,9 +556,9 @@ class Printer { | |
if (!this.format.retainLines) return; | ||
|
||
// catch up to this nodes newline if we're behind | ||
const pos = loc ? loc[prop] : null; | ||
if (pos?.line != null) { | ||
const count = pos.line - this._buf.getCurrentLine(); | ||
const line = loc?.[prop]?.line; | ||
if (line != null) { | ||
const count = line - this._buf.getCurrentLine(); | ||
|
||
for (let i = 0; i < count; i++) { | ||
this._newline(); | ||
|
@@ -655,19 +658,13 @@ class Printer { | |
this._insideAux = node.loc == undefined; | ||
this._maybeAddAuxComment(this._insideAux && !oldInAux); | ||
|
||
let shouldPrintParens = false; | ||
if (forceParens) { | ||
shouldPrintParens = true; | ||
} else if ( | ||
format.retainFunctionParens && | ||
nodeType === "FunctionExpression" && | ||
node.extra && | ||
node.extra.parenthesized | ||
) { | ||
shouldPrintParens = true; | ||
} else { | ||
shouldPrintParens = needsParens(node, parent, this._printStack); | ||
} | ||
const shouldPrintParens = | ||
forceParens || | ||
(format.retainFunctionParens && | ||
nodeType === "FunctionExpression" && | ||
node.extra?.parenthesized) || | ||
needsParens(node, parent, this._printStack); | ||
|
||
if (shouldPrintParens) { | ||
this.token("("); | ||
this._endsWithInnerRaw = false; | ||
|
@@ -895,12 +892,14 @@ class Printer { | |
} | ||
|
||
_printNewline(newLine: boolean, opts: AddNewlinesOptions) { | ||
const format = this.format; | ||
|
||
// Fast path since 'this.newline' does nothing when not tracking lines. | ||
if (this.format.retainLines || this.format.compact) return; | ||
if (format.retainLines || format.compact) return; | ||
|
||
// Fast path for concise since 'this.newline' just inserts a space when | ||
// concise formatting is in use. | ||
if (this.format.concise) { | ||
if (format.concise) { | ||
this.space(); | ||
return; | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...ression/comment-before-parentheses-return-arg-createParenthesizedExpressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"retainLines": true, | ||
"createParenthesizedExpressions": true | ||
"parserOpts": { "createParenthesizedExpressions": true } | ||
} |
13 changes: 7 additions & 6 deletions
13
...regression/comment-before-parentheses-return-arg-createParenthesizedExpressions/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
function assertElement(assertFn, shouldBeElement, opt_message) { | ||
return (/** @type {!Ele ment} */ | ||
return (/** @type {!Ele ment} */( | ||
assertType_( | ||
assertFn, | ||
shouldBeElement, | ||
isElement(shouldBeElement), | ||
'Element expected', | ||
opt_message)); | ||
|
||
|
||
opt_message | ||
) | ||
)); | ||
} | ||
|
||
const slot = /** @type {!HTMLSlotElement} */e.target; | ||
const slot = /** @type {!HTMLSlotElement} */(e.target); | ||
|
||
assertElement( | ||
/** @type {Element} */el); | ||
/** @type {Element} */(el) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../sourcemaps/comment-before-parentheses-return-arg-createParenthesizedExpressions/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function assertElement(assertFn, shouldBeElement, opt_message) { | ||
return /** @type {!Ele ment} */ ( | ||
assertType_( | ||
assertFn, | ||
shouldBeElement, | ||
isElement(shouldBeElement), | ||
'Element expected', | ||
opt_message | ||
) | ||
); | ||
} | ||
|
||
const slot = /** @type {!HTMLSlotElement} */ (e.target); | ||
|
||
assertElement( | ||
/** @type {Element} */ (el), | ||
); |
5 changes: 5 additions & 0 deletions
5
...rcemaps/comment-before-parentheses-return-arg-createParenthesizedExpressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"retainLines": true, | ||
"parserOpts": { "createParenthesizedExpressions": true }, | ||
"sourceMaps": true | ||
} |
17 changes: 17 additions & 0 deletions
17
...sourcemaps/comment-before-parentheses-return-arg-createParenthesizedExpressions/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function assertElement(assertFn, shouldBeElement, opt_message) { | ||
return (/** @type {!Ele ment} */( | ||
assertType_( | ||
assertFn, | ||
shouldBeElement, | ||
isElement(shouldBeElement), | ||
'Element expected', | ||
opt_message | ||
) | ||
)); | ||
} | ||
|
||
const slot = /** @type {!HTMLSlotElement} */(e.target); | ||
|
||
assertElement( | ||
/** @type {Element} */(el) | ||
); |
22 changes: 22 additions & 0 deletions
22
...maps/comment-before-parentheses-return-arg-createParenthesizedExpressions/source-map.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"version": 3, | ||
"names": [ | ||
"assertElement", | ||
"assertFn", | ||
"shouldBeElement", | ||
"opt_message", | ||
"assertType_", | ||
"isElement", | ||
"slot", | ||
"e", | ||
"target", | ||
"el" | ||
], | ||
"sources": [ | ||
"fixtures/sourcemaps/comment-before-parentheses-return-arg-createParenthesizedExpressions/input.js" | ||
], | ||
"sourcesContent": [ | ||
"function assertElement(assertFn, shouldBeElement, opt_message) {\n return /** @type {!Ele\tment} */ (\n\t assertType_(\n\t assertFn,\n\t\t shouldBeElement,\n\t\t isElement(shouldBeElement),\n\t\t 'Element expected',\n\t\t opt_message\n\t )\n\t);\n}\n\nconst slot = /** @type {!HTMLSlotElement} */ (e.target);\n\nassertElement(\n /** @type {Element} */ (el),\n);" | ||
], | ||
"mappings": "AAAA,SAASA,aAAaA,CAACC,QAAQ,EAAEC,eAAe,EAAEC,WAAW,EAAE;EAC7D,OAAO,yBAAyB;IAC/BC,WAAW;IACTH,QAAQ;IACTC,eAAe;IACfG,SAAS,CAACH,eAAe,CAAC;IAC1B,kBAAkB;IAClBC;IACD;IACF,CAAC;AACF;;AAEA,MAAMG,IAAI,GAAG,+BAAgC,CAACC,CAAC,CAACC,MAAM,CAAC;;AAEvDR,aAAa;AACX,sBAAuB,CAACS,EAAE;AAC5B,CAAC" | ||
} |
17 changes: 17 additions & 0 deletions
17
...s/babel-generator/test/fixtures/sourcemaps/comment-before-parentheses-return-arg/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function assertElement(assertFn, shouldBeElement, opt_message) { | ||
return /** @type {!Ele ment} */ ( | ||
assertType_( | ||
assertFn, | ||
shouldBeElement, | ||
isElement(shouldBeElement), | ||
'Element expected', | ||
opt_message | ||
) | ||
); | ||
} | ||
|
||
const slot = /** @type {!HTMLSlotElement} */ (e.target); | ||
|
||
assertElement( | ||
/** @type {Element} */ (el), | ||
); |
4 changes: 4 additions & 0 deletions
4
...bel-generator/test/fixtures/sourcemaps/comment-before-parentheses-return-arg/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"retainLines": true, | ||
"sourceMaps": true | ||
} |
Oops, something went wrong.
@liuxingbaoyu after this line, which arrived within
"@babel/generator": "7.21.5"
,I started to face a webpack build failure with error message:
After downgrade it back to
7.21.4
- everything works.As far as I debuged, looks like it fails on processing Angular's component, which has simple
template: "{{ dateNumber }}\n"
Not going to submit an issue, because I don't have standalone reproduce. But may be you, as author, can imagine what could go wrong?
In my case error somes from
@jridgewell/trace-mapping
where it tries to wire source map to source location {line:32, column: -1}, so -1 is unacceptable.