mirror of
https://github.com/swc-project/swc.git
synced 2024-12-22 21:21:31 +03:00
test(es/transform/jest): Ensure that sourcemap is working (#3864)
This commit is contained in:
parent
add86a7e6a
commit
fc87f43507
@ -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">
|
||||
|
@ -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
|
||||
}
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,329 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _exportNames = {
|
||||
node: true,
|
||||
node: true
|
||||
};
|
||||
exports.seq = exports.sources = exports.source = exports.header = exports.stage = exports.opener = exports.trustBox = exports.create = exports.node = void 0;
|
||||
var swcHelpers = require("@swc/helpers");
|
||||
var _abstractBuilders = require("./AbstractBuilders");
|
||||
var _builderUtils = require("./Builder.utils");
|
||||
var _elementBuilder = require("./ElementBuilder");
|
||||
var _node = swcHelpers.interopRequireWildcard(require("./BodyNodesBuilder"));
|
||||
Object.keys(_node).forEach(function(key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
if (key in exports && exports[key] === _node[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _node[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
exports.node = _node;
|
||||
const create = ()=>new BodyBuilder()
|
||||
;
|
||||
exports.create = create;
|
||||
const trustBox = ()=>new TrustBoxBuilder()
|
||||
;
|
||||
exports.trustBox = trustBox;
|
||||
const opener = ()=>new OpenerBuilder()
|
||||
;
|
||||
exports.opener = opener;
|
||||
const stage = ()=>new BodyStageBuilder()
|
||||
;
|
||||
exports.stage = stage;
|
||||
const header = ()=>new BodyHeaderBuilder()
|
||||
;
|
||||
exports.header = header;
|
||||
const source = (nodes = [])=>new ArticleSourceBuilder(...nodes)
|
||||
;
|
||||
exports.source = source;
|
||||
const sources = ()=>new ArticleSourcesBuilder()
|
||||
;
|
||||
exports.sources = sources;
|
||||
const seq = {
|
||||
stage: ()=>new BodyStageSeqBuilder()
|
||||
,
|
||||
source: ()=>new ArticleSourceSeqBuilder()
|
||||
};
|
||||
exports.seq = seq;
|
||||
var _stages = new WeakMap(), _trustBox = new WeakMap(), _disclaimer = new WeakMap(), _articleSources = new WeakMap();
|
||||
class BodyBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
stages(...stages) {
|
||||
swcHelpers.classPrivateFieldSet(this, _stages, stages.map(_builderUtils.mapBuildArg));
|
||||
return this;
|
||||
}
|
||||
trustBox(trustBox1) {
|
||||
swcHelpers.classPrivateFieldSet(this, _trustBox, (0, _builderUtils).mapBuildArg(trustBox1));
|
||||
return this;
|
||||
}
|
||||
disclaimer(disclaimer) {
|
||||
swcHelpers.classPrivateFieldSet(this, _disclaimer, disclaimer?.map(_builderUtils.mapBuildArg));
|
||||
return this;
|
||||
}
|
||||
articleSources(articleSources) {
|
||||
swcHelpers.classPrivateFieldSet(this, _articleSources, (0, _builderUtils).mapBuildArg(articleSources));
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
stages: swcHelpers.classPrivateFieldGet(this, _stages),
|
||||
trustBox: swcHelpers.classPrivateFieldGet(this, _trustBox),
|
||||
disclaimer: swcHelpers.classPrivateFieldGet(this, _disclaimer),
|
||||
articleSources: swcHelpers.classPrivateFieldGet(this, _articleSources)
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _stages, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _trustBox, {
|
||||
writable: true,
|
||||
value: undefined
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _disclaimer, {
|
||||
writable: true,
|
||||
value: undefined
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _articleSources, {
|
||||
writable: true,
|
||||
value: undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
var _nodes = new WeakMap(), _hidden = new WeakMap();
|
||||
class TrustBoxBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
nodes(nodes) {
|
||||
swcHelpers.classPrivateFieldSet(this, _nodes, nodes.map(_builderUtils.mapBuildArg));
|
||||
return this;
|
||||
}
|
||||
hidden(hidden) {
|
||||
swcHelpers.classPrivateFieldSet(this, _hidden, hidden.map(_builderUtils.mapBuildArg));
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
nodes: swcHelpers.classPrivateFieldGet(this, _nodes),
|
||||
hidden: swcHelpers.classPrivateFieldGet(this, _hidden)
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _nodes, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _hidden, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
}
|
||||
}
|
||||
var _element = new WeakMap();
|
||||
class OpenerBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
element(element) {
|
||||
swcHelpers.classPrivateFieldSet(this, _element, (0, _builderUtils).mapBuildArg(element));
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
element: swcHelpers.classPrivateFieldGet(this, _element)
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _element, {
|
||||
writable: true,
|
||||
value: (0, _elementBuilder).image().build()
|
||||
});
|
||||
}
|
||||
}
|
||||
var _nodes1 = new WeakMap(), _header = new WeakMap(), _companions = new WeakMap(), _commercialsEndOfStage = new WeakMap();
|
||||
class BodyStageSeqBuilder extends _abstractBuilders.AbstractSeqBuilder {
|
||||
nodes(nodes) {
|
||||
swcHelpers.classPrivateFieldSet(this, _nodes1, nodes.map(_builderUtils.mapBuildArgs));
|
||||
return this;
|
||||
}
|
||||
header(header1) {
|
||||
swcHelpers.classPrivateFieldSet(this, _header, (0, _builderUtils).mapBuildArgs(header1 ?? []));
|
||||
return this;
|
||||
}
|
||||
companions(companions) {
|
||||
swcHelpers.classPrivateFieldSet(this, _companions, companions.map(_builderUtils.mapBuildArgs));
|
||||
return this;
|
||||
}
|
||||
commercialsEndOfStage(commercialsEndOfStage) {
|
||||
swcHelpers.classPrivateFieldSet(this, _commercialsEndOfStage, commercialsEndOfStage.map(_builderUtils.mapBuildArgs));
|
||||
return this;
|
||||
}
|
||||
buildListItem(seqNextElement) {
|
||||
return {
|
||||
id: (0, _builderUtils).hash('bodyStage', swcHelpers.classPrivateFieldGet(this, _nodes1), swcHelpers.classPrivateFieldGet(this, _companions), swcHelpers.classPrivateFieldGet(this, _commercialsEndOfStage), swcHelpers.classPrivateFieldGet(this, _header)),
|
||||
nodes: seqNextElement.array(swcHelpers.classPrivateFieldGet(this, _nodes1)),
|
||||
header: seqNextElement.maybe(swcHelpers.classPrivateFieldGet(this, _header)),
|
||||
companions: seqNextElement.array(swcHelpers.classPrivateFieldGet(this, _companions)),
|
||||
commercialsEndOfStage: seqNextElement.array(swcHelpers.classPrivateFieldGet(this, _commercialsEndOfStage))
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _nodes1, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _header, {
|
||||
writable: true,
|
||||
value: undefined
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _companions, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _commercialsEndOfStage, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
}
|
||||
}
|
||||
var _seqBuilder = new WeakMap();
|
||||
class BodyStageBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
nodes(nodes) {
|
||||
swcHelpers.classPrivateFieldGet(this, _seqBuilder).nodes([
|
||||
nodes
|
||||
]);
|
||||
return this;
|
||||
}
|
||||
header(header2) {
|
||||
if (header2) {
|
||||
swcHelpers.classPrivateFieldGet(this, _seqBuilder).header([
|
||||
header2
|
||||
]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
companions(companions) {
|
||||
swcHelpers.classPrivateFieldGet(this, _seqBuilder).companions([
|
||||
companions
|
||||
]);
|
||||
return this;
|
||||
}
|
||||
commercialsEndOfStage(commercialsEndOfStage) {
|
||||
swcHelpers.classPrivateFieldGet(this, _seqBuilder).commercialsEndOfStage([
|
||||
commercialsEndOfStage
|
||||
]);
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return swcHelpers.classPrivateFieldGet(this, _seqBuilder).build();
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _seqBuilder, {
|
||||
writable: true,
|
||||
value: new BodyStageSeqBuilder()
|
||||
});
|
||||
}
|
||||
}
|
||||
var _variant = new WeakMap(), _opener = new WeakMap();
|
||||
class BodyHeaderBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
variant(variant) {
|
||||
swcHelpers.classPrivateFieldSet(this, _variant, variant);
|
||||
return this;
|
||||
}
|
||||
opener(opener1) {
|
||||
swcHelpers.classPrivateFieldSet(this, _opener, (0, _builderUtils).mapBuildArg(opener1));
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
variant: swcHelpers.classPrivateFieldGet(this, _variant),
|
||||
opener: swcHelpers.classPrivateFieldGet(this, _opener)
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _variant, {
|
||||
writable: true,
|
||||
value: 'full'
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _opener, {
|
||||
writable: true,
|
||||
value: undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
var _nodes2 = new WeakMap();
|
||||
class ArticleSourceSeqBuilder extends _abstractBuilders.AbstractSeqBuilder {
|
||||
nodes(nodes) {
|
||||
swcHelpers.classPrivateFieldSet(this, _nodes2, nodes.map(_builderUtils.mapBuildArgs));
|
||||
return this;
|
||||
}
|
||||
buildListItem(seqNextElement) {
|
||||
const id = (0, _builderUtils).hash('article-source', swcHelpers.classPrivateFieldGet(this, _nodes2));
|
||||
return {
|
||||
id,
|
||||
nodes: seqNextElement.array(swcHelpers.classPrivateFieldGet(this, _nodes2))
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _nodes2, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
}
|
||||
}
|
||||
var _seqBuilder1 = new WeakMap();
|
||||
class ArticleSourceBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
nodes(...nodes) {
|
||||
swcHelpers.classPrivateFieldGet(this, _seqBuilder1).nodes([
|
||||
nodes
|
||||
]);
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return swcHelpers.classPrivateFieldGet(this, _seqBuilder1).build();
|
||||
}
|
||||
constructor(...nodes){
|
||||
super();
|
||||
swcHelpers.classPrivateFieldInit(this, _seqBuilder1, {
|
||||
writable: true,
|
||||
value: new ArticleSourceSeqBuilder()
|
||||
});
|
||||
this.nodes(...nodes);
|
||||
}
|
||||
}
|
||||
var _nodes3 = new WeakMap(), _hidden1 = new WeakMap();
|
||||
class ArticleSourcesBuilder extends _abstractBuilders.AbstractBuilder {
|
||||
nodes(...nodes) {
|
||||
swcHelpers.classPrivateFieldSet(this, _nodes3, nodes.map(_builderUtils.mapBuildArg));
|
||||
return this;
|
||||
}
|
||||
hidden(...hidden) {
|
||||
swcHelpers.classPrivateFieldSet(this, _hidden1, hidden.map(_builderUtils.mapBuildArg));
|
||||
return this;
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
nodes: swcHelpers.classPrivateFieldGet(this, _nodes3),
|
||||
hidden: swcHelpers.classPrivateFieldGet(this, _hidden1)
|
||||
};
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
swcHelpers.classPrivateFieldInit(this, _nodes3, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
swcHelpers.classPrivateFieldInit(this, _hidden1, {
|
||||
writable: true,
|
||||
value: []
|
||||
});
|
||||
}
|
||||
}
|
@ -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": "inline"
|
||||
}
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user