Skip to content

Commit

Permalink
test(es/transform/jest): Ensure that sourcemap is working (#3864)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Mar 5, 2022
1 parent add86a7 commit fc87f43
Show file tree
Hide file tree
Showing 9 changed files with 1,271 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p align="center">
<a href="https://www.npmjs.com/package/@swc/core">
<img alt="npm Downloads" src="https://img.shields.io/npm/dw/@swc/core">
<img alt="npm Downloads" src="https://img.shields.io/npm/dm/@swc/core">
</a>
<a href="https://crates.io/crates/swc_ecma_parser">
<img alt="undefined" src="https://img.shields.io/crates/d/swc_ecma_parser.svg?label=crates.io%20downloads">
Expand Down
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/sourcemap/issue-3854/1-true/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"test": ".*.ts$",
"jsc": {
"target": "es2020",
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": false,
"dynamicImport": false
},
"externalHelpers": true,
"transform": {
"hidden": {
"jest": true
}
}
},
"module": {
"type": "commonjs"
},
"sourceMaps": true
}
256 changes: 256 additions & 0 deletions crates/swc/tests/fixture/sourcemap/issue-3854/1-true/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
import { AbstractBuilder, AbstractSeqBuilder } from './AbstractBuilders';
import { hash, mapBuildArg, mapBuildArgs } from './Builder.utils';
import { image } from './ElementBuilder';

import type {
Body,
BodyStage,
TrustBox,
RichText,
Opener,
BodyHeader,
Stage,
ArticleSource,
ArticleSources,
} from '@paper/models';
import type { BuildArg, BuildArgs, CreateBuilder, SeqElement, SeqNextElementConverter } from './types';

/**
* @deprecated use {Builder.body.node.img()}
*/
export * from './BodyNodesBuilder';
export * as node from './BodyNodesBuilder';

export const create: CreateBuilder<BodyBuilder> = () => new BodyBuilder();
export const trustBox: CreateBuilder<TrustBoxBuilder> = () => new TrustBoxBuilder();
export const opener: CreateBuilder<OpenerBuilder> = () => new OpenerBuilder();
export const stage: CreateBuilder<BodyStageBuilder> = () => new BodyStageBuilder();
export const header: CreateBuilder<BodyHeaderBuilder> = () => new BodyHeaderBuilder();
export const source: CreateBuilder<ArticleSourceBuilder, BuildArgs<RichText.Node>> = (
nodes: BuildArgs<RichText.Node> = [],
) => new ArticleSourceBuilder(...nodes);
export const sources: CreateBuilder<ArticleSourcesBuilder> = () => new ArticleSourcesBuilder();

export const seq = {
stage: (() => new BodyStageSeqBuilder()) as CreateBuilder<BodyStageSeqBuilder>,
source: (() => new ArticleSourceSeqBuilder()) as CreateBuilder<ArticleSourceSeqBuilder>,
} as const;

class BodyBuilder extends AbstractBuilder<Body> {
#stages: BodyStage[] = [];
#trustBox?: TrustBox = undefined;
#disclaimer?: RichText.Node[] = undefined;
#articleSources?: ArticleSources = undefined;

stages(...stages: BuildArgs<BodyStage>): this {
this.#stages = stages.map(mapBuildArg);
return this;
}

trustBox(trustBox?: BuildArg<TrustBox>): this {
this.#trustBox = mapBuildArg(trustBox);
return this;
}

disclaimer(disclaimer?: BuildArgs<RichText.Node>): this {
this.#disclaimer = disclaimer?.map(mapBuildArg);
return this;
}

articleSources(articleSources?: BuildArg<ArticleSources>): this {
this.#articleSources = mapBuildArg(articleSources);
return this;
}

build(): Body {
return {
stages: this.#stages,
trustBox: this.#trustBox,
disclaimer: this.#disclaimer,
articleSources: this.#articleSources,
};
}
}

class TrustBoxBuilder extends AbstractBuilder<TrustBox> {
#nodes: RichText.Node[] = [];
#hidden: RichText.Node[] = [];

nodes(nodes: BuildArgs<RichText.Node>): this {
this.#nodes = nodes.map(mapBuildArg);
return this;
}

hidden(hidden: BuildArgs<RichText.Node>): this {
this.#hidden = hidden.map(mapBuildArg);
return this;
}

build(): TrustBox {
return {
nodes: this.#nodes,
hidden: this.#hidden,
};
}
}

class OpenerBuilder extends AbstractBuilder<Opener> {
#element: Opener['element'] = image().build();

element(element: BuildArg<Opener['element']>): this {
this.#element = mapBuildArg(element);
return this;
}

build(): Opener {
return {
element: this.#element,
};
}
}

class BodyStageSeqBuilder extends AbstractSeqBuilder<BodyStage> {
#nodes: SeqElement<RichText.Node[]> = [];
#header?: SeqElement<BodyHeader> = undefined;
#companions: SeqElement<Stage.CompanionItem[]> = [];
#commercialsEndOfStage: SeqElement<RichText.Node[]> = [];

nodes(nodes: SeqElement<BuildArgs<RichText.Node>>): this {
this.#nodes = nodes.map(mapBuildArgs);
return this;
}

header(header?: SeqElement<BuildArg<BodyHeader>>): this {
this.#header = mapBuildArgs(header ?? []);
return this;
}

companions(companions: SeqElement<BuildArgs<Stage.CompanionItem>>): this {
this.#companions = companions.map(mapBuildArgs);
return this;
}

commercialsEndOfStage(commercialsEndOfStage: SeqElement<BuildArgs<RichText.Node>>): this {
this.#commercialsEndOfStage = commercialsEndOfStage.map(mapBuildArgs);
return this;
}

buildListItem(seqNextElement: SeqNextElementConverter): BodyStage {
return {
id: hash('bodyStage', this.#nodes, this.#companions, this.#commercialsEndOfStage, this.#header),
nodes: seqNextElement.array(this.#nodes),
header: seqNextElement.maybe(this.#header),
companions: seqNextElement.array(this.#companions),
commercialsEndOfStage: seqNextElement.array(this.#commercialsEndOfStage),
};
}
}

class BodyStageBuilder extends AbstractBuilder<BodyStage> {
#seqBuilder: BodyStageSeqBuilder = new BodyStageSeqBuilder();

nodes(nodes: BuildArgs<RichText.Node>): this {
this.#seqBuilder.nodes([nodes]);
return this;
}

header(header?: BuildArg<BodyHeader>): this {
if (header) {
this.#seqBuilder.header([header]);
}
return this;
}

companions(companions: BuildArgs<Stage.CompanionItem>): this {
this.#seqBuilder.companions([companions]);
return this;
}

commercialsEndOfStage(commercialsEndOfStage: BuildArgs<RichText.Node>): this {
this.#seqBuilder.commercialsEndOfStage([commercialsEndOfStage]);
return this;
}

build(): BodyStage {
return this.#seqBuilder.build();
}
}

class BodyHeaderBuilder extends AbstractBuilder<BodyHeader> {
#variant: BodyHeader['variant'] = 'full';
#opener?: Opener = undefined;

variant(variant: BodyHeader['variant']): this {
this.#variant = variant;
return this;
}

opener(opener: BuildArg<Opener>): this {
this.#opener = mapBuildArg(opener);
return this;
}

build(): BodyHeader {
return {
variant: this.#variant,
opener: this.#opener,
};
}
}

class ArticleSourceSeqBuilder extends AbstractSeqBuilder<ArticleSource> {
#nodes: SeqElement<RichText.Node[]> = [];

nodes(nodes: SeqElement<BuildArgs<RichText.Node>>): this {
this.#nodes = nodes.map(mapBuildArgs);
return this;
}

buildListItem(seqNextElement: SeqNextElementConverter): ArticleSource {
const id = hash('article-source', this.#nodes);
return {
id,
nodes: seqNextElement.array(this.#nodes),
};
}
}

class ArticleSourceBuilder extends AbstractBuilder<ArticleSource> {
#seqBuilder: ArticleSourceSeqBuilder = new ArticleSourceSeqBuilder();

constructor(...nodes: BuildArgs<RichText.Node>) {
super();
this.nodes(...nodes);
}

nodes(...nodes: BuildArgs<RichText.Node>): this {
this.#seqBuilder.nodes([nodes]);
return this;
}

build(): ArticleSource {
return this.#seqBuilder.build();
}
}

class ArticleSourcesBuilder extends AbstractBuilder<ArticleSources> {
#nodes: ArticleSource[] = [];
#hidden: ArticleSource[] = [];

nodes(...nodes: BuildArgs<ArticleSource>): this {
this.#nodes = nodes.map(mapBuildArg);
return this;
}

hidden(...hidden: BuildArgs<ArticleSource>): this {
this.#hidden = hidden.map(mapBuildArg);
return this;
}

build(): ArticleSources {
return {
nodes: this.#nodes,
hidden: this.#hidden,
};
}
}
Loading

1 comment on commit fc87f43

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: fc87f43 Previous: 6f076e4 Ratio
full_es2015 212858320 ns/iter (± 14942520) 188513156 ns/iter (± 10514390) 1.13
full_es2016 212531742 ns/iter (± 15445304) 187804755 ns/iter (± 5462928) 1.13
full_es2017 209930969 ns/iter (± 8747139) 186909777 ns/iter (± 5815177) 1.12
full_es2018 208545375 ns/iter (± 11342183) 185517385 ns/iter (± 13705672) 1.12
full_es2019 206794529 ns/iter (± 11091341) 184262131 ns/iter (± 5220243) 1.12
full_es2020 189864895 ns/iter (± 7190769) 171657599 ns/iter (± 3252929) 1.11
full_es3 282563878 ns/iter (± 13607307) 248295518 ns/iter (± 6499486) 1.14
full_es5 266611927 ns/iter (± 12277836) 235555733 ns/iter (± 8621816) 1.13
parser 835299 ns/iter (± 117633) 716713 ns/iter (± 20858) 1.17

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.