Skip to content

Commit

Permalink
fix(es/parser): Preserve comment positions with leading semicolon (#1…
Browse files Browse the repository at this point in the history
…0019)

**Related issue:**

- Closes: #10018 
- Related: #3720
  • Loading branch information
magic-akari authored Feb 10, 2025
1 parent 7d7319f commit c9937b6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/cool-eggs-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_parser: patch
---

fix(es/parser): Preserve comment positions with leading semicolon
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-10xxx/10018/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": true
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
3 changes: 3 additions & 0 deletions crates/swc/tests/fixture/issues-10xxx/10018/input/idnex.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @jsxImportSource foo */
;
<a />
3 changes: 3 additions & 0 deletions crates/swc/tests/fixture/issues-10xxx/10018/output/idnex.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var _require = require("foo/jsx-runtime"), _jsx = _require.jsx;
;
_jsx("a", {});
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/tests/test262/f2142c1dabd961c1.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
;
/* not comment*/ ;
a-- > 1;
9 changes: 8 additions & 1 deletion crates/swc_ecma_minifier/tests/benches-full/lodash.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
(function() {
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/ (function() {
/** Error message constants. */ var undefined, FUNC_ERROR_TEXT = 'Expected a function', HASH_UNDEFINED = '__lodash_hash_undefined__', PLACEHOLDER = '__lodash_placeholder__', INFINITY = 1 / 0, NAN = 0 / 0, wrapFlags = [
[
'ary',
Expand Down
38 changes: 7 additions & 31 deletions crates/swc_ecma_minifier/tests/benches-full/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -13111,7 +13111,7 @@ function(global, factory) {
void 0 === skeleton ? console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton) : child.bind(skeleton, child.bindMatrix);
}
});
} /* DEPRECATED */ , _proto.setTexturePath = function(value) {
}, _proto.setTexturePath = function(value) {
return console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().'), this.setResourcePath(value);
}, ObjectLoader;
}(Loader), TEXTURE_MAPPING = {
Expand Down Expand Up @@ -15420,33 +15420,15 @@ function(global, factory) {
void 0 === sigma && (sigma = 0), void 0 === near && (near = 0.1), void 0 === far && (far = 100), _oldTarget = this._renderer.getRenderTarget();
var cubeUVRenderTarget = this._allocateTargets();
return this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget), sigma > 0 && this._blur(cubeUVRenderTarget, 0, 0, sigma), this._applyPMREM(cubeUVRenderTarget), this._cleanup(cubeUVRenderTarget), cubeUVRenderTarget;
} /**
* Generates a PMREM from an equirectangular texture, which can be either LDR
* (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
* as this matches best with the 256 x 256 cubemap output.
*/ , _proto.fromEquirectangular = function(equirectangular) {
}, _proto.fromEquirectangular = function(equirectangular) {
return this._fromTexture(equirectangular);
} /**
* Generates a PMREM from an cubemap texture, which can be either LDR
* (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
* as this matches best with the 256 x 256 cubemap output.
*/ , _proto.fromCubemap = function(cubemap) {
}, _proto.fromCubemap = function(cubemap) {
return this._fromTexture(cubemap);
} /**
* Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
* your texture's network fetch for increased concurrency.
*/ , _proto.compileCubemapShader = function() {
}, _proto.compileCubemapShader = function() {
null === this._cubemapShader && (this._cubemapShader = _getCubemapShader(), this._compileMaterial(this._cubemapShader));
} /**
* Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
* your texture's network fetch for increased concurrency.
*/ , _proto.compileEquirectangularShader = function() {
}, _proto.compileEquirectangularShader = function() {
null === this._equirectShader && (this._equirectShader = _getEquirectShader(), this._compileMaterial(this._equirectShader));
} /**
* Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
* so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
* one of them will cause any others to also become unusable.
*/ , _proto.dispose = function() {
}, _proto.dispose = function() {
this._blurMaterial.dispose(), null !== this._cubemapShader && this._cubemapShader.dispose(), null !== this._equirectShader && this._equirectShader.dispose();
for(var i = 0; i < _lodPlanes.length; i++)_lodPlanes[i].dispose();
} // private interface
Expand Down Expand Up @@ -15514,13 +15496,7 @@ function(global, factory) {
this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
}
renderer.autoClear = autoClear;
} /**
* This is a two-pass Gaussian blur for a cubemap. Normally this is done
* vertically and horizontally, but this breaks down on a cube. Here we apply
* the blur latitudinally (around the poles), and then longitudinally (towards
* the poles) to approximate the orthogonally-separable blur. It is least
* accurate at the poles, but still does a decent job.
*/ , _proto._blur = function(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
}, _proto._blur = function(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
var pingPongRenderTarget = this._pingPongRenderTarget;
this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis), this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
}, _proto._halfBlur = function(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/lexer/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl Lexer<'_> {

self.skip_space::<false>();

if self.input.is_byte(b';') {
if !self.state.had_line_break && self.input.is_byte(b';') {
is_for_next = false;
}

Expand Down

0 comments on commit c9937b6

Please sign in to comment.