diff --git a/bundler/tests/deno-exec/issue-8302/entry.ts b/bundler/tests/deno-exec/issue-8302/entry.ts new file mode 100644 index 000000000000..f5daf6bbecdb --- /dev/null +++ b/bundler/tests/deno-exec/issue-8302/entry.ts @@ -0,0 +1,2 @@ +import axiod from 'https://deno.land/x/axiod/mod.ts'; +console.log(axiod) \ No newline at end of file diff --git a/bundler/tests/fixture/dynamic/input/entry.ts b/bundler/tests/fixture/dynamic/input/entry.ts index 2d3dfc46c09e..76332615bc45 100644 --- a/bundler/tests/fixture/dynamic/input/entry.ts +++ b/bundler/tests/fixture/dynamic/input/entry.ts @@ -1,3 +1,4 @@ const a = import('./dep') -console.log(a) \ No newline at end of file +console.log(a) + diff --git a/ecmascript/codegen/src/lib.rs b/ecmascript/codegen/src/lib.rs index 3e8b394ef3ca..bd2378198e83 100644 --- a/ecmascript/codegen/src/lib.rs +++ b/ecmascript/codegen/src/lib.rs @@ -2493,6 +2493,10 @@ fn escape_with_source<'s>( s: &'s str, single_quote: Option, ) -> String { + if target <= JscTarget::Es5 { + return escape_without_source(s, target, single_quote.unwrap_or(false)); + } + if span.is_dummy() { return escape_without_source(s, target, single_quote.unwrap_or(false)); } diff --git a/ecmascript/codegen/src/text_writer.rs b/ecmascript/codegen/src/text_writer.rs index 67e5ef4c4e55..7b265d768065 100644 --- a/ecmascript/codegen/src/text_writer.rs +++ b/ecmascript/codegen/src/text_writer.rs @@ -105,4 +105,8 @@ where fn write_punct(&mut self, s: &'static str) -> Result { (**self).write_punct(s) } + + fn target(&self) -> JscTarget { + (**self).target() + } } diff --git a/ecmascript/codegen/src/text_writer/basic_impl.rs b/ecmascript/codegen/src/text_writer/basic_impl.rs index 75953bb92748..cc954db7a799 100644 --- a/ecmascript/codegen/src/text_writer/basic_impl.rs +++ b/ecmascript/codegen/src/text_writer/basic_impl.rs @@ -1,6 +1,7 @@ use super::{Result, WriteJs}; use std::io::{self, Write}; use swc_common::{sync::Lrc, BytePos, LineCol, SourceMap, Span}; +use swc_ecma_parser::JscTarget; /// /// ----- @@ -19,6 +20,7 @@ pub struct JsWriter<'a, W: Write> { srcmap: Option<&'a mut Vec<(BytePos, LineCol)>>, wr: W, written_bytes: usize, + target: JscTarget, } impl<'a, W: Write> JsWriter<'a, W> { @@ -27,6 +29,16 @@ impl<'a, W: Write> JsWriter<'a, W> { new_line: &'a str, wr: W, srcmap: Option<&'a mut Vec<(BytePos, LineCol)>>, + ) -> Self { + Self::with_target(cm, new_line, wr, srcmap, JscTarget::Es2020) + } + + pub fn with_target( + cm: Lrc, + new_line: &'a str, + wr: W, + srcmap: Option<&'a mut Vec<(BytePos, LineCol)>>, + target: JscTarget, ) -> Self { JsWriter { _cm: cm, @@ -38,6 +50,7 @@ impl<'a, W: Write> JsWriter<'a, W> { srcmap, wr, written_bytes: 0, + target, } } @@ -187,6 +200,10 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> { self.write(None, s)?; Ok(()) } + + fn target(&self) -> JscTarget { + self.target + } } fn compute_line_starts(s: &str) -> Vec { diff --git a/ecmascript/transforms/compat/src/es2020/class_properties/private_field.rs b/ecmascript/transforms/compat/src/es2020/class_properties/private_field.rs index 04bdb418d759..c89ecda11bc5 100644 --- a/ecmascript/transforms/compat/src/es2020/class_properties/private_field.rs +++ b/ecmascript/transforms/compat/src/es2020/class_properties/private_field.rs @@ -372,11 +372,22 @@ impl<'a> Fold for FieldAccessFolder<'a> { .fold_children_with(self) } } - Expr::Member(e) => self.fold_private_get(e, None).0, + Expr::Member(e) => { + let e = e.fold_with(self); + self.fold_private_get(e, None).0 + } _ => e.fold_children_with(self), } } + fn fold_member_expr(&mut self, mut e: MemberExpr) -> MemberExpr { + e.obj = e.obj.fold_with(self); + if e.computed { + e.prop = e.prop.fold_with(self); + } + e + } + fn fold_pat(&mut self, p: Pat) -> Pat { if let Pat::Expr(expr) = &p { if let Expr::Member(me) = &**expr { diff --git a/ecmascript/transforms/compat/tests/es2020_class_properties.rs b/ecmascript/transforms/compat/tests/es2020_class_properties.rs index 5911b7e7da91..a3392dc22f06 100644 --- a/ecmascript/transforms/compat/tests/es2020_class_properties.rs +++ b/ecmascript/transforms/compat/tests/es2020_class_properties.rs @@ -4840,3 +4840,71 @@ export class HygieneTest { }", ok_if_code_eq ); + +test!( + syntax(), + |_| class_properties(), + issue_1306_1, + r#" + class Animal { + #name; + + constructor(name) { + this.#name = name + } + + noise() { + return this.#name + } + } +"#, + " + class Animal { + noise() { + return _classPrivateFieldGet(this, _name); + } + constructor(name){ + _name.set(this, { + writable: true, + value: void 0 + }); + _classPrivateFieldSet(this, _name, name); + } + } + var _name = new WeakMap(); +" +); + +test!( + syntax(), + |_| class_properties(), + issue_1306_2, + r#" + class Animal { + #name; + + constructor(name) { + this.#name = name + } + + noise() { + return this.#name.toUpperCase() + } + } +"#, + " + class Animal { + noise() { + return _classPrivateFieldGet(this, _name).toUpperCase(); + } + constructor(name){ + _name.set(this, { + writable: true, + value: void 0 + }); + _classPrivateFieldSet(this, _name, name); + } + } + var _name = new WeakMap(); +" +); diff --git a/src/builder.rs b/src/builder.rs index 54e7ca2687c8..05d8a4621344 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,4 +1,5 @@ use crate::config::{GlobalPassOption, JscTarget, ModuleConfig}; +use compat::es2020::export_namespace_from; use either::Either; use std::{collections::HashMap, sync::Arc}; use swc_atoms::JsWord; @@ -176,6 +177,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { self.pass, compat_pass, compat::reserved_words::reserved_words(), + Optional::new(export_namespace_from(), need_interop_analysis), // module / helper Optional::new( modules::import_analysis::import_analyzer(), diff --git a/src/codegen.rs b/src/codegen.rs deleted file mode 100644 index d8d43abbe78e..000000000000 --- a/src/codegen.rs +++ /dev/null @@ -1,80 +0,0 @@ -use swc_common::Span; -use swc_ecma_codegen::{text_writer::WriteJs, Result}; -use swc_ecma_parser::JscTarget; - -pub(crate) struct WriterWapper -where - W: WriteJs, -{ - pub target: JscTarget, - pub inner: W, -} - -impl WriteJs for WriterWapper -where - W: WriteJs, -{ - fn increase_indent(&mut self) -> Result { - self.inner.increase_indent() - } - - fn decrease_indent(&mut self) -> Result { - self.inner.decrease_indent() - } - - fn write_semi(&mut self) -> Result { - self.inner.write_semi() - } - - fn write_space(&mut self) -> Result { - self.inner.write_space() - } - - fn write_keyword(&mut self, span: Option, s: &'static str) -> Result { - self.inner.write_keyword(span, s) - } - - fn write_operator(&mut self, s: &str) -> Result { - self.inner.write_operator(s) - } - - fn write_param(&mut self, s: &str) -> Result { - self.inner.write_param(s) - } - - fn write_property(&mut self, s: &str) -> Result { - self.inner.write_property(s) - } - - fn write_line(&mut self) -> Result { - self.inner.write_line() - } - - fn write_lit(&mut self, span: Span, s: &str) -> Result { - self.inner.write_lit(span, s) - } - - fn write_comment(&mut self, span: Span, s: &str) -> Result { - self.inner.write_comment(span, s) - } - - fn write_str_lit(&mut self, span: Span, s: &str) -> Result { - self.inner.write_str_lit(span, s) - } - - fn write_str(&mut self, s: &str) -> Result { - self.inner.write_str(s) - } - - fn write_symbol(&mut self, span: Span, s: &str) -> Result { - self.inner.write_symbol(span, s) - } - - fn write_punct(&mut self, s: &'static str) -> Result { - self.inner.write_punct(s) - } - - fn target(&self) -> JscTarget { - self.target - } -} diff --git a/src/lib.rs b/src/lib.rs index 4e5c1756bc09..ea277bb75044 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,6 @@ use swc_ecma_transforms::{ use swc_ecma_visit::FoldWith; mod builder; -mod codegen; pub mod config; pub struct Compiler { @@ -207,19 +206,17 @@ impl Compiler { cfg: swc_ecma_codegen::Config { minify }, comments: if minify { None } else { Some(&self.comments) }, cm: self.cm.clone(), - wr: Box::new(self::codegen::WriterWapper { + wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::with_target( + self.cm.clone(), + "\n", + &mut buf, + if source_map.enabled() { + Some(&mut src_map_buf) + } else { + None + }, target, - inner: swc_ecma_codegen::text_writer::JsWriter::new( - self.cm.clone(), - "\n", - &mut buf, - if source_map.enabled() { - Some(&mut src_map_buf) - } else { - None - }, - ), - }), + )), }; node.emit_with(&mut emitter) diff --git a/tests/fixture/codegen/escape/case-1/output/index.js b/tests/fixture/codegen/escape/case-1/output/index.js index fe6fb0c7d1e7..fef6ecaf3659 100644 --- a/tests/fixture/codegen/escape/case-1/output/index.js +++ b/tests/fixture/codegen/escape/case-1/output/index.js @@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; -var _default = "\nvoid main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n"; +var _default = "\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n"; exports.default = _default; diff --git a/tests/fixture/codegen/escape/case-2/output/index.js b/tests/fixture/codegen/escape/case-2/output/index.js index 999a8665fc4c..8eea8c77f35c 100644 --- a/tests/fixture/codegen/escape/case-2/output/index.js +++ b/tests/fixture/codegen/escape/case-2/output/index.js @@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; -var _default = "\n// Analytical approximation of the DFG LUT, one half of the\n// split-sum approximation used in indirect specular lighting.\n// via 'environmentBRDF' from \"Physically Based Shading on Mobile\"\n// https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n return vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n // based upon Frostbite 3 Moving to Physically-based Rendering\n // page 32, equation 26: E[window1]\n // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\n // this is intended to be used on spot and point lights who are represented as luminous intensity\n // but who must be converted to luminous irradiance for surface lighting calculation\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n if( cutoffDistance > 0.0 ) {\n distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n }\n return distanceFalloff;\n#else\n if( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n} // validated\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n // Original approximation by Christophe Schlick '94\n // float fresnel = pow( 1.0 - dotLH, 5.0 );\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n} // validated\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n // See F_Schlick\n float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n return Fr * fresnel + F0;\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney’s reparameterization\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n // geometry term (normalized) = G(l)⋅G(v) / 4(n⋅l)(n⋅v)\n // also see #12151\n float a2 = pow2( alpha );\n float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n return 1.0 / ( gl * gv );\n} // validated\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n // dotNL and dotNV are explicitly swapped. This is not a mistake.\n float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n return 0.5 / max( gv + gl, EPSILON );\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney’s reparameterization\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n return RECIPROCAL_PI * a2 / pow2( denom );\n}\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n float alpha = pow2( roughness ); // UE4's roughness\n vec3 halfDir = normalize( incidentLight.direction + viewDir );\n float dotNL = saturate( dot( normal, incidentLight.direction ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n} // validated\n// Rect Area Light\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\n// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\n// code: https://github.com/selfshadow/ltc_code/\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n float dotNV = saturate( dot( N, V ) );\n // texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )\n vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n uv = uv * LUT_SCALE + LUT_BIAS;\n return uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n // Real-Time Area Lighting: a Journey from Research to Production (p.102)\n // An approximation of the form factor of a horizon-clipped rectangle.\n float l = length( f );\n return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n float x = dot( v1, v2 );\n float y = abs( x );\n // rational polynomial approximation to theta / sin( theta ) / 2PI\n float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n float b = 3.4175940 + ( 4.1616724 + y ) * y;\n float v = a / b;\n float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n return cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n // bail if point is on back side of plane of light\n // assumes ccw winding order of light vertices\n vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n vec3 lightNormal = cross( v1, v2 );\n if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n // construct orthonormal basis around N\n vec3 T1, T2;\n T1 = normalize( V - N * dot( V, N ) );\n T2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system\n // compute transform\n mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n // transform rect\n vec3 coords[ 4 ];\n coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n // project rect onto sphere\n coords[ 0 ] = normalize( coords[ 0 ] );\n coords[ 1 ] = normalize( coords[ 1 ] );\n coords[ 2 ] = normalize( coords[ 2 ] );\n coords[ 3 ] = normalize( coords[ 3 ] );\n // calculate vector form factor\n vec3 vectorFormFactor = vec3( 0.0 );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n // adjust for horizon clipping\n float result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n/*\n // alternate method of adjusting for horizon clipping (see referece)\n // refactoring required\n float len = length( vectorFormFactor );\n float z = vectorFormFactor.z / len;\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n // tabulated horizon-clipped sphere, apparently...\n vec2 uv = vec2( z * 0.5 + 0.5, len );\n uv = uv * LUT_SCALE + LUT_BIAS;\n float scale = texture2D( ltc_2, uv ).w;\n float result = len * scale;\n*/\n return vec3( result );\n}\n// End Rect Area Light\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( normal, viewDir ) );\n vec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n return specularColor * brdf.x + brdf.y;\n} // validated\n// Fdez-Agüera's \"Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting\"\n// Approximates multiscattering in order to preserve energy.\n// http://www.jcgt.org/published/0008/01/03/\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n vec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n vec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n vec3 FssEss = F * brdf.x + brdf.y;\n float Ess = brdf.x + brdf.y;\n float Ems = 1.0 - Ess;\n vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21\n vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n singleScatter += FssEss;\n multiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n //float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n //float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n} // validated\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n return sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94\nfloat D_Charlie(float roughness, float NoH) {\n // Estevez and Kulla 2017, \"Production Friendly Microfacet Sheen BRDF\"\n float invAlpha = 1.0 / roughness;\n float cos2h = NoH * NoH;\n float sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136\nfloat V_Neubelt(float NoV, float NoL) {\n // Neubelt and Pettineo 2013, \"Crafting a Next-gen Material Pipeline for The Order: 1886\"\n return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n vec3 N = geometry.normal;\n vec3 V = geometry.viewDir;\n vec3 H = normalize( V + L );\n float dotNH = saturate( dot( N, H ) );\n return specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif\n"; +var _default = "\n// Analytical approximation of the DFG LUT, one half of the\n// split-sum approximation used in indirect specular lighting.\n// via 'environmentBRDF' from \"Physically Based Shading on Mobile\"\n// https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t// based upon Frostbite 3 Moving to Physically-based Rendering\n\t// page 32, equation 26: E[window1]\n\t// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\n\t// this is intended to be used on spot and point lights who are represented as luminous intensity\n\t// but who must be converted to luminous irradiance for surface lighting calculation\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n} // validated\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\t// Original approximation by Christophe Schlick '94\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\n\t// Optimized variant (presented by Epic at SIGGRAPH '13)\n\t// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n} // validated\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\t// See F_Schlick\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney\u2019s reparameterization\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\t// geometry term (normalized) = G(l)\u22c5G(v) / 4(n\u22c5l)(n\u22c5v)\n\t// also see #12151\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n} // validated\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney\u2019s reparameterization\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness ); // UE4's roughness\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n} // validated\n// Rect Area Light\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\n// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\n// code: https://github.com/selfshadow/ltc_code/\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\t// texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\t// Real-Time Area Lighting: a Journey from Research to Production (p.102)\n\t// An approximation of the form factor of a horizon-clipped rectangle.\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\t// rational polynomial approximation to theta / sin( theta ) / 2PI\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\t// bail if point is on back side of plane of light\n\t// assumes ccw winding order of light vertices\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\t// construct orthonormal basis around N\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system\n\t// compute transform\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\t// transform rect\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\t// project rect onto sphere\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\t// calculate vector form factor\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\t// adjust for horizon clipping\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n/*\n\t// alternate method of adjusting for horizon clipping (see referece)\n\t// refactoring required\n\tfloat len = length( vectorFormFactor );\n\tfloat z = vectorFormFactor.z / len;\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\t// tabulated horizon-clipped sphere, apparently...\n\tvec2 uv = vec2( z * 0.5 + 0.5, len );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\tfloat scale = texture2D( ltc_2, uv ).w;\n\tfloat result = len * scale;\n*/\n\treturn vec3( result );\n}\n// End Rect Area Light\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n} // validated\n// Fdez-Ag\xfcera's \"Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting\"\n// Approximates multiscattering in order to preserve energy.\n// http://www.jcgt.org/published/0008/01/03/\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21\n\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n\t// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\t//float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\t//float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94\nfloat D_Charlie(float roughness, float NoH) {\n\t// Estevez and Kulla 2017, \"Production Friendly Microfacet Sheen BRDF\"\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\n// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136\nfloat V_Neubelt(float NoV, float NoL) {\n\t// Neubelt and Pettineo 2013, \"Crafting a Next-gen Material Pipeline for The Order: 1886\"\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif\n"; exports.default = _default; diff --git a/tests/fixture/issue-1227/case-1/input/.swcrc b/tests/fixture/issue-1227/case-1/input/.swcrc new file mode 100644 index 000000000000..00e1fefb99a7 --- /dev/null +++ b/tests/fixture/issue-1227/case-1/input/.swcrc @@ -0,0 +1,5 @@ +{ + "jsc": { + "target": "es5" + } +} diff --git a/tests/fixture/issue-1227/case-1/input/index.js b/tests/fixture/issue-1227/case-1/input/index.js new file mode 100644 index 000000000000..4cdfacd7614a --- /dev/null +++ b/tests/fixture/issue-1227/case-1/input/index.js @@ -0,0 +1 @@ +const foo = "\u{a0}"; diff --git a/tests/fixture/issue-1227/case-1/output/index.js b/tests/fixture/issue-1227/case-1/output/index.js new file mode 100644 index 000000000000..de235a7fd2b5 --- /dev/null +++ b/tests/fixture/issue-1227/case-1/output/index.js @@ -0,0 +1 @@ +var foo = "\xa0"; diff --git a/tests/fixture/issue-1233/case-1/output/index.js b/tests/fixture/issue-1233/case-1/output/index.js index 54a7d9955184..1cda37671e6c 100644 --- a/tests/fixture/issue-1233/case-1/output/index.js +++ b/tests/fixture/issue-1233/case-1/output/index.js @@ -1,5 +1,5 @@ function Component() { return React.createElement("div", { - name: "A\n B" + name: "A\n\n B" }); } diff --git a/tests/fixture/issue-1276/output/index.ts b/tests/fixture/issue-1276/output/index.ts index 8890daa6c166..bbce7f966058 100644 --- a/tests/fixture/issue-1276/output/index.ts +++ b/tests/fixture/issue-1276/output/index.ts @@ -1,2 +1,2 @@ -var a = "\/\/"; +var a = "//"; console.log(a); diff --git a/tests/fixture/issue-1306-1/input/.swcrc b/tests/fixture/issue-1306-1/input/.swcrc new file mode 100644 index 000000000000..b13af4912184 --- /dev/null +++ b/tests/fixture/issue-1306-1/input/.swcrc @@ -0,0 +1,8 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es5" + } +} diff --git a/tests/fixture/issue-1306-1/input/index.ts b/tests/fixture/issue-1306-1/input/index.ts new file mode 100644 index 000000000000..1ed7444266d4 --- /dev/null +++ b/tests/fixture/issue-1306-1/input/index.ts @@ -0,0 +1,11 @@ +class Animal { + readonly #name: string + + constructor(name: string) { + this.#name = name + } + + public noise() { + return this.#name.toUpperCase() + } +} \ No newline at end of file diff --git a/tests/fixture/issue-1306-1/output/index.ts b/tests/fixture/issue-1306-1/output/index.ts new file mode 100644 index 000000000000..3dde02c6934d --- /dev/null +++ b/tests/fixture/issue-1306-1/output/index.ts @@ -0,0 +1,57 @@ +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} +function _classPrivateFieldGet(receiver, privateMap) { + if (!privateMap.has(receiver)) { + throw new TypeError("attempted to get private field on non-instance"); + } + return privateMap.get(receiver).value; +} +function _classPrivateFieldSet(receiver, privateMap, value) { + if (!privateMap.has(receiver)) { + throw new TypeError("attempted to set private field on non-instance"); + } + var descriptor = privateMap.get(receiver); + if (!descriptor.writable) { + throw new TypeError("attempted to set read only private field"); + } + descriptor.value = value; + return value; +} +function _defineProperties(target, props) { + for(var i = 0; i < props.length; i++){ + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} +var Animal = function() { + "use strict"; + function Animal(name) { + _classCallCheck(this, Animal); + _name.set(this, { + writable: true, + value: void 0 + }); + _classPrivateFieldSet(this, _name, name); + } + _createClass(Animal, [ + { + key: "noise", + value: function noise() { + return _classPrivateFieldGet(this, _name).toUpperCase(); + } + } + ]); + return Animal; +}(); +var _name = new WeakMap(); diff --git a/tests/fixture/issue-1306-2/input/.swcrc b/tests/fixture/issue-1306-2/input/.swcrc new file mode 100644 index 000000000000..fe015f618c6d --- /dev/null +++ b/tests/fixture/issue-1306-2/input/.swcrc @@ -0,0 +1,8 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "target": "es5" + } +} diff --git a/tests/fixture/issue-1306-2/input/index.js b/tests/fixture/issue-1306-2/input/index.js new file mode 100644 index 000000000000..fda2cb0aa1e4 --- /dev/null +++ b/tests/fixture/issue-1306-2/input/index.js @@ -0,0 +1,11 @@ +class Animal { + #name; + + constructor(name) { + this.#name = name + } + + noise() { + return this.#name.toUpperCase() + } +} \ No newline at end of file diff --git a/tests/fixture/issue-1306-2/output/index.js b/tests/fixture/issue-1306-2/output/index.js new file mode 100644 index 000000000000..3dde02c6934d --- /dev/null +++ b/tests/fixture/issue-1306-2/output/index.js @@ -0,0 +1,57 @@ +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} +function _classPrivateFieldGet(receiver, privateMap) { + if (!privateMap.has(receiver)) { + throw new TypeError("attempted to get private field on non-instance"); + } + return privateMap.get(receiver).value; +} +function _classPrivateFieldSet(receiver, privateMap, value) { + if (!privateMap.has(receiver)) { + throw new TypeError("attempted to set private field on non-instance"); + } + var descriptor = privateMap.get(receiver); + if (!descriptor.writable) { + throw new TypeError("attempted to set read only private field"); + } + descriptor.value = value; + return value; +} +function _defineProperties(target, props) { + for(var i = 0; i < props.length; i++){ + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} +var Animal = function() { + "use strict"; + function Animal(name) { + _classCallCheck(this, Animal); + _name.set(this, { + writable: true, + value: void 0 + }); + _classPrivateFieldSet(this, _name, name); + } + _createClass(Animal, [ + { + key: "noise", + value: function noise() { + return _classPrivateFieldGet(this, _name).toUpperCase(); + } + } + ]); + return Animal; +}(); +var _name = new WeakMap(); diff --git a/tests/fixture/issue-1307/input/.swcrc b/tests/fixture/issue-1307/input/.swcrc new file mode 100644 index 000000000000..054da276d247 --- /dev/null +++ b/tests/fixture/issue-1307/input/.swcrc @@ -0,0 +1,21 @@ +{ + "exclude": ".*.test.ts$", + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": false, + "dynamicImport": true + }, + "target": "es2020", + "loose": true + }, + "module": { + "type": "commonjs", + "strict": false, + "strictMode": true, + "lazy": false, + "noInterop": false + }, + "minify": false +} diff --git a/tests/fixture/issue-1307/input/index.ts b/tests/fixture/issue-1307/input/index.ts new file mode 100644 index 000000000000..21d1c5480a20 --- /dev/null +++ b/tests/fixture/issue-1307/input/index.ts @@ -0,0 +1 @@ +export * as foo from "./foo"; diff --git a/tests/fixture/issue-1307/output/index.ts b/tests/fixture/issue-1307/output/index.ts new file mode 100644 index 000000000000..4412c2e4f888 --- /dev/null +++ b/tests/fixture/issue-1307/output/index.ts @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.foo = void 0; +var _foo = _interopRequireWildcard(require("./foo")); +function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = { + }; + if (obj != null) { + for(var key in obj){ + if (Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : { + }; + if (desc.get || desc.set) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + } + newObj.default = obj; + return newObj; + } +} +exports.foo = _foo; diff --git a/tests/fixture/issue-1314/input/.swcrc b/tests/fixture/issue-1314/input/.swcrc new file mode 100644 index 000000000000..992d34071bf8 --- /dev/null +++ b/tests/fixture/issue-1314/input/.swcrc @@ -0,0 +1,16 @@ +{ + "jsc": { + "target": "es2015", + "parser": { + "syntax": "ecmascript", + "privateMethod": false, + "functionBind": false, + "exportDefaultFrom": false, + "exportNamespaceFrom": false, + "decorators": false, + "decoratorsBeforeExport": false, + "topLevelAwait": false, + "importMeta": false + } + } +} diff --git a/tests/fixture/issue-1314/input/index.js b/tests/fixture/issue-1314/input/index.js new file mode 100644 index 000000000000..6fb93f4f9a1e --- /dev/null +++ b/tests/fixture/issue-1314/input/index.js @@ -0,0 +1,11 @@ +const a = { + method() { + const string = ` + width: ${Math.abs(this.currentX - this.startX - left)}px; + height: ${Math.abs(this.currentY - this.realtimeStartY - top)}px; + top: ${Math.min(this.currentY - top, this.realtimeStartY) + this.scrollTop}px; + left: ${Math.min(this.currentX - left, this.startX) + this.scrollLeft}px + `; + + } +} \ No newline at end of file diff --git a/tests/fixture/issue-1314/output/index.js b/tests/fixture/issue-1314/output/index.js new file mode 100644 index 000000000000..2b810e77692f --- /dev/null +++ b/tests/fixture/issue-1314/output/index.js @@ -0,0 +1,5 @@ +var a = { + method: function() { + var string = "\n width: ".concat(Math.abs(this.currentX - this.startX - left), "px;\n height: ").concat(Math.abs(this.currentY - this.realtimeStartY - top), "px;\n top: ").concat(Math.min(this.currentY - top, this.realtimeStartY) + this.scrollTop, "px;\n left: ").concat(Math.min(this.currentX - left, this.startX) + this.scrollLeft, "px\n "); + } +};