bestax-migrate 2.40.1 → 2.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/sources/_shared/bestax-floor.d.ts +49 -0
- package/dist/sources/_shared/bestax-floor.d.ts.map +1 -1
- package/dist/sources/_shared/bestax-floor.js +84 -0
- package/dist/sources/_shared/bestax-import.d.ts +16 -1
- package/dist/sources/_shared/bestax-import.d.ts.map +1 -1
- package/dist/sources/_shared/bestax-import.js +67 -2
- package/dist/sources/_shared/bestax-release.d.ts +27 -0
- package/dist/sources/_shared/bestax-release.d.ts.map +1 -0
- package/dist/sources/_shared/bestax-release.js +79 -0
- package/dist/sources/_shared/deps-common.d.ts +11 -9
- package/dist/sources/_shared/deps-common.d.ts.map +1 -1
- package/dist/sources/_shared/deps-common.js +25 -11
- package/dist/sources/_shared/imports.d.ts +50 -1
- package/dist/sources/_shared/imports.d.ts.map +1 -1
- package/dist/sources/_shared/imports.js +121 -0
- package/dist/sources/_shared/jsx-utils.d.ts +8 -0
- package/dist/sources/_shared/jsx-utils.d.ts.map +1 -1
- package/dist/sources/_shared/jsx-utils.js +13 -0
- package/dist/sources/_shared/props.d.ts +13 -0
- package/dist/sources/_shared/props.d.ts.map +1 -1
- package/dist/sources/_shared/props.js +36 -0
- package/dist/sources/bloomer/deps.d.ts +2 -3
- package/dist/sources/bloomer/deps.d.ts.map +1 -1
- package/dist/sources/bloomer/deps.js +9 -9
- package/dist/sources/bloomer/mapping.d.ts +3 -22
- package/dist/sources/bloomer/mapping.d.ts.map +1 -1
- package/dist/sources/bloomer/mapping.js +5 -45
- package/dist/sources/bloomer/transform.d.ts +3 -2
- package/dist/sources/bloomer/transform.d.ts.map +1 -1
- package/dist/sources/bloomer/transform.js +50 -39
- package/dist/sources/bulma-classes/deps.d.ts +2 -2
- package/dist/sources/bulma-classes/deps.js +2 -2
- package/dist/sources/rbx/deps.d.ts +2 -3
- package/dist/sources/rbx/deps.d.ts.map +1 -1
- package/dist/sources/rbx/deps.js +9 -9
- package/dist/sources/rbx/index.d.ts.map +1 -1
- package/dist/sources/rbx/index.js +6 -0
- package/dist/sources/rbx/mapping.d.ts +8 -0
- package/dist/sources/rbx/mapping.d.ts.map +1 -1
- package/dist/sources/rbx/mapping.js +53 -0
- package/dist/sources/rbx/transform.d.ts +3 -2
- package/dist/sources/rbx/transform.d.ts.map +1 -1
- package/dist/sources/rbx/transform.js +162 -72
- package/dist/sources/react-bulma-components/deps.d.ts +2 -2
- package/dist/sources/react-bulma-components/deps.d.ts.map +1 -1
- package/dist/sources/react-bulma-components/deps.js +10 -9
- package/dist/sources/react-bulma-components/transform.d.ts +3 -2
- package/dist/sources/react-bulma-components/transform.d.ts.map +1 -1
- package/dist/sources/react-bulma-components/transform.js +46 -63
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ The codemod uses [jscodeshift](https://github.com/facebook/jscodeshift) to:
|
|
|
62
62
|
- for `bulma-classes` on an HTML page, write a React module beside it (`index.html` → `index.tsx`, or `.jsx` when the package isn't TypeScript) whose default export is the page's body as a component (`LoginPage`), converted as the same markup written as JSX would be. The page is never changed and an existing module is never overwritten; the head, the `<html>` and `<body>` attributes, the stylesheets and scripts it loads, and inline handlers are left as `html-*` TODOs, except that under `--css bestax` or `--css bulma` the module imports the stylesheet in place of the page's Bulma `<link>`
|
|
63
63
|
- restructure patterns bestax models differently (`Table.Container`, Navbar dropdowns, `Form.Help`, icon-font children → `<Icon name=…>`)
|
|
64
64
|
- migrate stylesheets: CSS imports converge on `@allxsmith/bestax-bulma/bestax.css`, and SCSS files move from Bulma 0.9's `@import` + `$var !default` overrides to `@use 'bulma/sass' with (…)` plus `@use '@allxsmith/bestax-bulma/scss/extras'`
|
|
65
|
-
- update `package.json`: remove the source library, add `@allxsmith/bestax-bulma
|
|
65
|
+
- update `package.json`: remove the source library, add `@allxsmith/bestax-bulma` (or report the one you already declare or have installed when it is older than the release the migrated code is written for), raise a declared pre-1.0 `bulma` to `^1` (adding it only when your sources import `bulma/…` directly — otherwise it arrives transitively), and swap the dead `node-sass` for dart `sass` (no install is ever run). Migrating **rbx** is what frees an app from Bulma 0.7.5: rbx pinned it as a _direct_ dependency, so the app could not choose its own Bulma version at all. The four Bulma extensions rbx also pulled in (`bulma-badge`, `bulma-divider`, `bulma-pageloader`, `bulma-tooltip`) are **reported rather than removed** — bestax replaces all four, but a manifest entry is a deliberate declaration and your own Sass may import them. A **bloomer** app declared its own Bulma 0.6, which is what gets bumped. For **bulma-classes** there is no library to remove, and by default (`--css keep`) the app's Bulma version, Sass and stylesheet imports all stay: its own Bulma already styles every class a converted element renders. `--css bestax` or `--css bulma` moves it to Bulma v1 like the other sources
|
|
66
66
|
|
|
67
67
|
Anything without a safe automatic conversion is left in place with a `// TODO(bestax-migrate): …` comment, and the run ends with a report of every TODO by file and line. TODOs are expected output, not errors — resolve them with the migration guide ([react-bulma-components](https://bestax.io/docs/guides/getting-started/migration/react-bulma-components), [rbx](https://bestax.io/docs/guides/getting-started/migration/rbx), [bloomer](https://bestax.io/docs/guides/getting-started/migration/bloomer), [Bulma classes](https://bestax.io/docs/guides/getting-started/migration/bulma-classes)), or let the [`bestax-migrate` Agent Skill](https://bestax.io/docs/skills/intro) walk them for you:
|
|
68
68
|
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* refused. An override (`overrides`, `resolutions`, `pnpm.overrides`) that
|
|
14
14
|
* pins bestax-bulma lower isn't read.
|
|
15
15
|
*/
|
|
16
|
+
import type { ASTPath, JSXElement } from 'jscodeshift';
|
|
17
|
+
import { type TransformContext } from './jsx-utils.js';
|
|
16
18
|
import { type RunManifests } from './manifests.js';
|
|
17
19
|
export interface BestaxPackage {
|
|
18
20
|
/** The package's directory, absolute. */
|
|
@@ -29,6 +31,53 @@ export interface BestaxPackage {
|
|
|
29
31
|
export declare function readBestaxPackages(targets: string[]): BestaxPackage[];
|
|
30
32
|
/** The same, from the manifests a run has already found. */
|
|
31
33
|
export declare function bestaxPackagesOf({ manifests, nearest, }: RunManifests): BestaxPackage[];
|
|
34
|
+
/**
|
|
35
|
+
* Targets that keep their own class beside a `className` only from a
|
|
36
|
+
* bestax-bulma release, by target. An older release writes the `className`
|
|
37
|
+
* in place of the class that makes the element work. bulma-classes' class
|
|
38
|
+
* map holds the same release as `classNameSince`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const CLASSNAME_SINCE: Readonly<Record<string, string>>;
|
|
41
|
+
/**
|
|
42
|
+
* The release `target` keeps its class beside a `className` from, when
|
|
43
|
+
* `floor` (`bestaxFloorFor`'s) doesn't reach it, or undefined when a
|
|
44
|
+
* `className` is safe on it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function classNameWaitsFor(target: string, floor: string | undefined): string | undefined;
|
|
47
|
+
/** What keeps an element off its bestax target (`heldForRelease`). */
|
|
48
|
+
export interface ReleaseHold {
|
|
49
|
+
/** The release the target takes a `className` from. */
|
|
50
|
+
since: string;
|
|
51
|
+
/** A spread, rather than a `className` of its own, could replace its class. */
|
|
52
|
+
spread: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Why an element mapped onto `target` can't convert yet: the target keeps
|
|
56
|
+
* its own class beside a `className` only from a release `floor` doesn't
|
|
57
|
+
* reach, and the element carries a `className`, or a spread that may hold
|
|
58
|
+
* one, which an older release writes in place of that class.
|
|
59
|
+
*/
|
|
60
|
+
export declare function heldForRelease(element: JSXElement, target: string | undefined, floor: string | undefined): ReleaseHold | undefined;
|
|
61
|
+
/** How a TODO opens about the release `target` takes a `className` from. */
|
|
62
|
+
export declare function releaseRaise(target: string, since: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* The TODO on an element `heldForRelease` names: one that stays `source`'s,
|
|
65
|
+
* or one that converted anyway when `source` is left out.
|
|
66
|
+
*/
|
|
67
|
+
export declare function releaseHoldMessage(target: string, { since, spread }: ReleaseHold, source?: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Decides, for a reference to a component as a value, whether it waits for
|
|
70
|
+
* a release: where its `target` takes a `className` only from a release
|
|
71
|
+
* `floor` doesn't reach (`classNameWaitsFor`), whatever renders the
|
|
72
|
+
* reference can hand it one, which the codemod can't see. The returned
|
|
73
|
+
* function then writes a `value-reference` TODO naming the release at `at`
|
|
74
|
+
* and returns true when the reference stays `source`'s: `retain` is told
|
|
75
|
+
* which import it keeps (the local's imported name, `'*'` for a namespace).
|
|
76
|
+
* One reached through an alias (`viaAlias`) converts all the same, with the
|
|
77
|
+
* TODO, and gets false. A reference in a type (`typeof X`) renders nothing,
|
|
78
|
+
* so it converts with no TODO.
|
|
79
|
+
*/
|
|
80
|
+
export declare function makeReferenceHold(ctx: TransformContext, floor: string | undefined, source: string, retain: (imported: string) => void): (at: ASTPath, target: string, imported: string, viaAlias?: boolean) => boolean;
|
|
32
81
|
/**
|
|
33
82
|
* The oldest bestax-bulma release `file` can count on, or undefined when it
|
|
34
83
|
* can't count on one. `deps` is the run's manifest step, on unless false.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bestax-floor.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/bestax-floor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"bestax-floor.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/bestax-floor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAkBxB,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,KAAK,CAAC,EAAE,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AI,GACjC,CACD,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,OAAO,KACf,OAAO,CAcX;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,EACjB,IAAI,EAAE,OAAO,GACZ,MAAM,GAAG,SAAS,CAKpB"}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import fs from 'node:fs';
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import { BESTAX_FLOOR } from './deps-common.js';
|
|
19
|
+
import { addTodo } from './jsx-utils.js';
|
|
19
20
|
import { innermostAround, readManifests, } from './manifests.js';
|
|
20
21
|
import { compareVersions, rangeFloor } from './semver-range.js';
|
|
21
22
|
const NAME = '@allxsmith/bestax-bulma';
|
|
@@ -72,6 +73,89 @@ export function bestaxPackagesOf({ manifests, nearest, }) {
|
|
|
72
73
|
}
|
|
73
74
|
return packages;
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Targets that keep their own class beside a `className` only from a
|
|
78
|
+
* bestax-bulma release, by target. An older release writes the `className`
|
|
79
|
+
* in place of the class that makes the element work. bulma-classes' class
|
|
80
|
+
* map holds the same release as `classNameSince`.
|
|
81
|
+
*/
|
|
82
|
+
export const CLASSNAME_SINCE = {
|
|
83
|
+
'Pagination.Ellipsis': '5.78.4',
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The release `target` keeps its class beside a `className` from, when
|
|
87
|
+
* `floor` (`bestaxFloorFor`'s) doesn't reach it, or undefined when a
|
|
88
|
+
* `className` is safe on it.
|
|
89
|
+
*/
|
|
90
|
+
export function classNameWaitsFor(target, floor) {
|
|
91
|
+
const since = CLASSNAME_SINCE[target];
|
|
92
|
+
if (since === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
return floor && compareVersions(floor, since) >= 0 ? undefined : since;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Why an element mapped onto `target` can't convert yet: the target keeps
|
|
98
|
+
* its own class beside a `className` only from a release `floor` doesn't
|
|
99
|
+
* reach, and the element carries a `className`, or a spread that may hold
|
|
100
|
+
* one, which an older release writes in place of that class.
|
|
101
|
+
*/
|
|
102
|
+
export function heldForRelease(element, target, floor) {
|
|
103
|
+
const since = target && classNameWaitsFor(target, floor);
|
|
104
|
+
if (!since)
|
|
105
|
+
return undefined;
|
|
106
|
+
const attributes = element.openingElement.attributes ?? [];
|
|
107
|
+
const spread = attributes.some(a => a.type === 'JSXSpreadAttribute');
|
|
108
|
+
const own = attributes.some(a => a.type === 'JSXAttribute' && a.name.name === 'className');
|
|
109
|
+
return spread || own ? { since, spread } : undefined;
|
|
110
|
+
}
|
|
111
|
+
/** How a TODO opens about the release `target` takes a `className` from. */
|
|
112
|
+
export function releaseRaise(target, since) {
|
|
113
|
+
return `bestax \`${target}\` keeps its own class beside a \`className\` from @allxsmith/bestax-bulma ${since} on, and this project isn't sure to get ${since}`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The TODO on an element `heldForRelease` names: one that stays `source`'s,
|
|
117
|
+
* or one that converted anyway when `source` is left out.
|
|
118
|
+
*/
|
|
119
|
+
export function releaseHoldMessage(target, { since, spread }, source) {
|
|
120
|
+
const carries = spread
|
|
121
|
+
? 'a spread whose contents the codemod cannot read, where a `className` would replace that class'
|
|
122
|
+
: 'a `className`, which would replace that class';
|
|
123
|
+
return `${releaseRaise(target, since)}, and this element carries ${carries}${releaseAsk(since, source)}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* How a release TODO ends: what to declare, and that the code stays
|
|
127
|
+
* `source`'s until a re-run, or only what to declare when it converted.
|
|
128
|
+
*/
|
|
129
|
+
function releaseAsk(since, source) {
|
|
130
|
+
const declare = `declare \`@allxsmith/bestax-bulma\` at \`^${since}\` or later`;
|
|
131
|
+
return source
|
|
132
|
+
? `, so it stays ${source}'s: ${declare} and re-run`
|
|
133
|
+
: `: ${declare}`;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Decides, for a reference to a component as a value, whether it waits for
|
|
137
|
+
* a release: where its `target` takes a `className` only from a release
|
|
138
|
+
* `floor` doesn't reach (`classNameWaitsFor`), whatever renders the
|
|
139
|
+
* reference can hand it one, which the codemod can't see. The returned
|
|
140
|
+
* function then writes a `value-reference` TODO naming the release at `at`
|
|
141
|
+
* and returns true when the reference stays `source`'s: `retain` is told
|
|
142
|
+
* which import it keeps (the local's imported name, `'*'` for a namespace).
|
|
143
|
+
* One reached through an alias (`viaAlias`) converts all the same, with the
|
|
144
|
+
* TODO, and gets false. A reference in a type (`typeof X`) renders nothing,
|
|
145
|
+
* so it converts with no TODO.
|
|
146
|
+
*/
|
|
147
|
+
export function makeReferenceHold(ctx, floor, source, retain) {
|
|
148
|
+
return (at, target, imported, viaAlias = false) => {
|
|
149
|
+
const since = classNameWaitsFor(target, floor);
|
|
150
|
+
if (!since || at.parent?.node?.type === 'TSTypeQuery')
|
|
151
|
+
return false;
|
|
152
|
+
addTodo(ctx, at, 'value-reference', `${releaseRaise(target, since)}, and whatever renders this reference can give it a \`className\`, which would replace that class${releaseAsk(since, viaAlias ? undefined : source)}`);
|
|
153
|
+
if (viaAlias)
|
|
154
|
+
return false;
|
|
155
|
+
retain(imported);
|
|
156
|
+
return true;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
75
159
|
/**
|
|
76
160
|
* The oldest bestax-bulma release `file` can count on, or undefined when it
|
|
77
161
|
* can't count on one. `deps` is the run's manifest step, on unless false.
|
|
@@ -39,10 +39,25 @@ export declare function bestaxValueLocals(ctx: TransformContext, state: BestaxIm
|
|
|
39
39
|
export declare function placeBestaxImport(state: BestaxImportState, fresh: any | null, anchor: {
|
|
40
40
|
insertBefore(node: any): unknown;
|
|
41
41
|
}): void;
|
|
42
|
+
/**
|
|
43
|
+
* Say on a library import the transform keeps (at `importPath`) why it
|
|
44
|
+
* stays. Each component the file retains (`retained`, by imported name) is
|
|
45
|
+
* still used where the transform left a TODO of its own, for whatever reason
|
|
46
|
+
* that TODO gives (no bestax equivalent, a member the table doesn't know, a
|
|
47
|
+
* value it couldn't rewrite, a release the project may not get), so the note
|
|
48
|
+
* points at those rather than naming one reason. It names the ones this
|
|
49
|
+
* import brings in: a named import its own, a namespace import those no
|
|
50
|
+
* other import of the library names. An import that brings in none, such as
|
|
51
|
+
* a broken default binding or a namespace used as a value, gets no note: the
|
|
52
|
+
* TODO that keeps it is where it is used, or on the import itself. Call it
|
|
53
|
+
* once the import's specifiers are the ones it keeps.
|
|
54
|
+
*/
|
|
55
|
+
export declare function noteRetainedImport(ctx: TransformContext, importPath: any, retained: ReadonlySet<string>): void;
|
|
42
56
|
/**
|
|
43
57
|
* A pruned declaration takes its comments with it — a licence header, an
|
|
44
58
|
* eslint directive. Hand them to `carrier` (the bestax import that survives),
|
|
45
|
-
* or to the next statement, or keep them where they were.
|
|
59
|
+
* or to the next statement, or keep them where they were. A note
|
|
60
|
+
* `noteRetainedImport` wrote on it was about the import, so it goes with it.
|
|
46
61
|
*/
|
|
47
62
|
export declare function carryPrunedComments(node: any, importPath: any, carrier: any | null): void;
|
|
48
63
|
//# sourceMappingURL=bestax-import.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bestax-import.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/bestax-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIvD,eAAO,MAAM,MAAM,4BAA4B,CAAC;AAEhD,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,QAAQ,EAAE,GAAG,GAAG,SAAS,CAAC;IAC1B,mEAAmE;IACnE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,6DAA6D;IAC7D,SAAS,EAAE,GAAG,CAAC,MAAM,CAA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AgBZ;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,iBAAiB,GACvB,GAAG,CAAC,MAAM,CAAC,CASb;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,iBAAiB,EACxB,KAAK,EAAE,GAAG,GAAG,IAAI,EACjB,MAAM,EAAE;IAAE,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAA;CAAE,GAC3C,IAAI,CAyBN;AAmBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,gBAAgB,EACrB,UAAU,EAAE,GAAG,EACf,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAC5B,IAAI,CAoDN;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,GAAG,EACT,UAAU,EAAE,GAAG,EACf,OAAO,EAAE,GAAG,GAAG,IAAI,GAClB,IAAI,CAsBN"}
|
|
@@ -108,13 +108,78 @@ export function placeBestaxImport(state, fresh, anchor) {
|
|
|
108
108
|
}
|
|
109
109
|
state.existing.node.specifiers = [...current, ...appended];
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* How the note `noteRetainedImport` writes ends: first in this wording, then
|
|
113
|
+
* in an earlier release's, which a re-run replaces rather than adds to.
|
|
114
|
+
*/
|
|
115
|
+
const NOTE_ENDINGS = [
|
|
116
|
+
'still imported for what the other TODOs in this file flag; resolve those, then remove this import',
|
|
117
|
+
'no bestax-bulma equivalent yet — migrate and remove this import',
|
|
118
|
+
];
|
|
119
|
+
function isRetainedNote(comment) {
|
|
120
|
+
const text = String(comment?.value ?? '');
|
|
121
|
+
return (text.startsWith(' TODO(bestax-migrate): ') &&
|
|
122
|
+
NOTE_ENDINGS.some(ending => text.endsWith(ending)));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Say on a library import the transform keeps (at `importPath`) why it
|
|
126
|
+
* stays. Each component the file retains (`retained`, by imported name) is
|
|
127
|
+
* still used where the transform left a TODO of its own, for whatever reason
|
|
128
|
+
* that TODO gives (no bestax equivalent, a member the table doesn't know, a
|
|
129
|
+
* value it couldn't rewrite, a release the project may not get), so the note
|
|
130
|
+
* points at those rather than naming one reason. It names the ones this
|
|
131
|
+
* import brings in: a named import its own, a namespace import those no
|
|
132
|
+
* other import of the library names. An import that brings in none, such as
|
|
133
|
+
* a broken default binding or a namespace used as a value, gets no note: the
|
|
134
|
+
* TODO that keeps it is where it is used, or on the import itself. Call it
|
|
135
|
+
* once the import's specifiers are the ones it keeps.
|
|
136
|
+
*/
|
|
137
|
+
export function noteRetainedImport(ctx, importPath, retained) {
|
|
138
|
+
const node = importPath.node;
|
|
139
|
+
const named = (declaration) => (declaration.specifiers ?? [])
|
|
140
|
+
.filter((s) => s.type === 'ImportSpecifier')
|
|
141
|
+
.map((s) => nameOf(s.imported));
|
|
142
|
+
let names;
|
|
143
|
+
if ((node.specifiers ?? []).some((s) => s.type === 'ImportNamespaceSpecifier')) {
|
|
144
|
+
const elsewhere = new Set((importPath.parent?.node?.body ?? [])
|
|
145
|
+
.filter((other) => other !== node &&
|
|
146
|
+
other.type === 'ImportDeclaration' &&
|
|
147
|
+
other.source?.value === node.source?.value)
|
|
148
|
+
.flatMap(named));
|
|
149
|
+
names = [...retained].filter(name => !elsewhere.has(name));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
names = named(node).filter(name => retained.has(name));
|
|
153
|
+
}
|
|
154
|
+
const listed = [...new Set(names)].sort((a, b) => a.localeCompare(b));
|
|
155
|
+
const text = ` TODO(bestax-migrate): ${listed.join(', ')} ${listed.length === 1 ? 'is' : 'are'} ${NOTE_ENDINGS[0]}`;
|
|
156
|
+
// An earlier note is replaced where it was, so a re-run leaves the
|
|
157
|
+
// comments around it in their places.
|
|
158
|
+
const comments = [];
|
|
159
|
+
let placed = listed.length === 0;
|
|
160
|
+
for (const comment of node.comments ?? []) {
|
|
161
|
+
if (!isRetainedNote(comment)) {
|
|
162
|
+
comments.push(comment);
|
|
163
|
+
}
|
|
164
|
+
else if (!placed) {
|
|
165
|
+
comments.push(comment.value === text
|
|
166
|
+
? comment
|
|
167
|
+
: ctx.j.commentLine(text, comment.leading ?? true, comment.trailing ?? false));
|
|
168
|
+
placed = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!placed)
|
|
172
|
+
comments.push(ctx.j.commentLine(text, true, false));
|
|
173
|
+
node.comments = comments;
|
|
174
|
+
}
|
|
111
175
|
/**
|
|
112
176
|
* A pruned declaration takes its comments with it — a licence header, an
|
|
113
177
|
* eslint directive. Hand them to `carrier` (the bestax import that survives),
|
|
114
|
-
* or to the next statement, or keep them where they were.
|
|
178
|
+
* or to the next statement, or keep them where they were. A note
|
|
179
|
+
* `noteRetainedImport` wrote on it was about the import, so it goes with it.
|
|
115
180
|
*/
|
|
116
181
|
export function carryPrunedComments(node, importPath, carrier) {
|
|
117
|
-
const comments = node.comments ?? [];
|
|
182
|
+
const comments = (node.comments ?? []).filter((c) => !isRetainedNote(c));
|
|
118
183
|
if (comments.length === 0)
|
|
119
184
|
return;
|
|
120
185
|
const body = importPath.parent?.node?.body ?? [];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which @allxsmith/bestax-bulma release the migrated code is written for, and
|
|
3
|
+
* which one an app has installed (#2314).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The bestax-bulma release the migrated code is written for: the lowest one
|
|
7
|
+
* this CLI's own manifest depends on. The codemod writes every value the
|
|
8
|
+
* library it was built against takes (its value-union tests hold it to
|
|
9
|
+
* them), so an older release can drop one without a word.
|
|
10
|
+
*
|
|
11
|
+
* The manifest spells the dependency `workspace:^`, which `pnpm publish`
|
|
12
|
+
* rewrites to a caret on the library's version in the checkout it packs, and
|
|
13
|
+
* CI releases bulma-ui first in the same job, so a published CLI reads the
|
|
14
|
+
* release it was built with. Run from this repo, the protocol is still there,
|
|
15
|
+
* and it resolves the way `pnpm publish` resolves it, from the version of the
|
|
16
|
+
* library the workspace links. create-bestax's `libraryRange` (#1240) reads
|
|
17
|
+
* the range a scaffold gets from the same entry.
|
|
18
|
+
*/
|
|
19
|
+
export declare function builtFor(packageRoot?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* The version of the bestax-bulma Node loads for a package in `dir`: the one
|
|
22
|
+
* in the nearest `node_modules` at or above it. Undefined when none is
|
|
23
|
+
* installed there, as in a fresh clone or under Yarn Plug'n'Play, or when its
|
|
24
|
+
* manifest names no version this reads.
|
|
25
|
+
*/
|
|
26
|
+
export declare function installedVersion(dir: string): string | undefined;
|
|
27
|
+
//# sourceMappingURL=bestax-release.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bestax-release.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/bestax-release.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,WAAW,GAAE,MAAqB,GAAG,MAAM,CA2BnE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAehE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which @allxsmith/bestax-bulma release the migrated code is written for, and
|
|
3
|
+
* which one an app has installed (#2314).
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { rangeFloor } from './semver-range.js';
|
|
9
|
+
const NAME = '@allxsmith/bestax-bulma';
|
|
10
|
+
const WORKSPACE = 'workspace:';
|
|
11
|
+
// src/ and dist/ both sit directly under the package root, and this file is
|
|
12
|
+
// in sources/_shared/ under each.
|
|
13
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
|
14
|
+
function readManifest(file) {
|
|
15
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The bestax-bulma release the migrated code is written for: the lowest one
|
|
19
|
+
* this CLI's own manifest depends on. The codemod writes every value the
|
|
20
|
+
* library it was built against takes (its value-union tests hold it to
|
|
21
|
+
* them), so an older release can drop one without a word.
|
|
22
|
+
*
|
|
23
|
+
* The manifest spells the dependency `workspace:^`, which `pnpm publish`
|
|
24
|
+
* rewrites to a caret on the library's version in the checkout it packs, and
|
|
25
|
+
* CI releases bulma-ui first in the same job, so a published CLI reads the
|
|
26
|
+
* release it was built with. Run from this repo, the protocol is still there,
|
|
27
|
+
* and it resolves the way `pnpm publish` resolves it, from the version of the
|
|
28
|
+
* library the workspace links. create-bestax's `libraryRange` (#1240) reads
|
|
29
|
+
* the range a scaffold gets from the same entry.
|
|
30
|
+
*/
|
|
31
|
+
export function builtFor(packageRoot = PACKAGE_ROOT) {
|
|
32
|
+
const file = path.join(packageRoot, 'package.json');
|
|
33
|
+
const declared = readManifest(file).dependencies?.[NAME];
|
|
34
|
+
if (typeof declared !== 'string') {
|
|
35
|
+
throw new Error(`${file} declares no ${NAME} dependency.`);
|
|
36
|
+
}
|
|
37
|
+
let range = declared;
|
|
38
|
+
if (declared.startsWith(WORKSPACE)) {
|
|
39
|
+
const spec = declared.slice(WORKSPACE.length);
|
|
40
|
+
// `*`, `^` and `~` stand for the linked version, which `pnpm publish`
|
|
41
|
+
// writes on its own or after that operator; a range stays as written.
|
|
42
|
+
if (['*', '^', '~'].includes(spec)) {
|
|
43
|
+
const { version } = readManifest(path.join(packageRoot, 'node_modules', NAME, 'package.json'));
|
|
44
|
+
range = String(version);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
range = spec;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const floor = rangeFloor(range);
|
|
51
|
+
if (floor === null) {
|
|
52
|
+
throw new Error(`${file} depends on ${NAME} ${declared}, which names no lowest release.`);
|
|
53
|
+
}
|
|
54
|
+
return floor;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The version of the bestax-bulma Node loads for a package in `dir`: the one
|
|
58
|
+
* in the nearest `node_modules` at or above it. Undefined when none is
|
|
59
|
+
* installed there, as in a fresh clone or under Yarn Plug'n'Play, or when its
|
|
60
|
+
* manifest names no version this reads.
|
|
61
|
+
*/
|
|
62
|
+
export function installedVersion(dir) {
|
|
63
|
+
for (let at = path.resolve(dir);; at = path.dirname(at)) {
|
|
64
|
+
const file = path.join(at, 'node_modules', NAME, 'package.json');
|
|
65
|
+
if (fs.existsSync(file)) {
|
|
66
|
+
try {
|
|
67
|
+
const { version } = readManifest(file);
|
|
68
|
+
return typeof version === 'string'
|
|
69
|
+
? (rangeFloor(version) ?? undefined)
|
|
70
|
+
: undefined;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (path.dirname(at) === at)
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
* The package.json steps every source's manifest pass takes once the source
|
|
3
3
|
* library itself is dealt with: bring in bestax-bulma, move the app's Bulma to
|
|
4
4
|
* v1, report peer ranges bestax-bulma cannot install beside, and swap the
|
|
5
|
-
* dead node-sass for dart-sass.
|
|
6
|
-
* call it: no package manager is ever invoked.
|
|
5
|
+
* dead node-sass for dart-sass. No package manager is ever invoked.
|
|
7
6
|
*/
|
|
8
7
|
import type { TodoCollector } from '../../types.js';
|
|
9
8
|
/**
|
|
10
|
-
* The
|
|
11
|
-
* 5.78.4 `Pagination.Ellipsis` keeps its class beside a `className` (#2178).
|
|
9
|
+
* The bestax-bulma release the migrated code is written for (`builtFor`).
|
|
12
10
|
* The range the manifest step adds starts there, and `bestax-floor.ts` counts
|
|
13
11
|
* on it for a package that step writes.
|
|
14
12
|
*/
|
|
15
|
-
export declare const BESTAX_FLOOR
|
|
13
|
+
export declare const BESTAX_FLOOR: string;
|
|
16
14
|
export declare const BULMA_RANGE = "^1.0.4";
|
|
17
15
|
/** bestax-bulma's optional peer range for Font Awesome. */
|
|
18
16
|
export declare const FONT_AWESOME_PEER_RANGE = "^6.7.2 || ^7.0.0";
|
|
19
17
|
export declare const DEP_SECTIONS: readonly ["dependencies", "devDependencies"];
|
|
20
18
|
type Section = (typeof DEP_SECTIONS)[number];
|
|
21
19
|
export interface Manifest {
|
|
20
|
+
/** The package.json being edited. */
|
|
21
|
+
file: string;
|
|
22
22
|
/** The manifest being edited in place. */
|
|
23
23
|
next: Record<string, Record<string, string> | unknown>;
|
|
24
24
|
section(name: Section): Record<string, string> | undefined;
|
|
@@ -31,10 +31,12 @@ export interface Manifest {
|
|
|
31
31
|
}
|
|
32
32
|
export declare function openManifest(filePath: string, pkg: Record<string, unknown>, collector: TodoCollector | undefined): Manifest;
|
|
33
33
|
/**
|
|
34
|
-
* @allxsmith/bestax-bulma comes in as a runtime dependency.
|
|
35
|
-
* already
|
|
36
|
-
*
|
|
37
|
-
* the app's own step
|
|
34
|
+
* @allxsmith/bestax-bulma comes in as a runtime dependency. One the package
|
|
35
|
+
* already has, older than the release the migrated code is written for, is
|
|
36
|
+
* reported, not raised: an older major (`peer-deps`, since moving the app's
|
|
37
|
+
* existing bestax code across majors is the app's own step), and otherwise a
|
|
38
|
+
* declared range that starts below that release or an older copy the package
|
|
39
|
+
* loads (`deps`, left for the app to decide like the other reports there).
|
|
38
40
|
*/
|
|
39
41
|
export declare function addBestax(manifest: Manifest): void;
|
|
40
42
|
export interface BulmaOutcome {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deps-common.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/deps-common.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"deps-common.d.ts","sour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,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,OAAO,GAAG,SAAS,GACnC,YAAY,CA2Bd;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAqBzD;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAexD"}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* The package.json steps every source's manifest pass takes once the source
|
|
3
3
|
* library itself is dealt with: bring in bestax-bulma, move the app's Bulma to
|
|
4
4
|
* v1, report peer ranges bestax-bulma cannot install beside, and swap the
|
|
5
|
-
* dead node-sass for dart-sass.
|
|
6
|
-
* call it: no package manager is ever invoked.
|
|
5
|
+
* dead node-sass for dart-sass. No package manager is ever invoked.
|
|
7
6
|
*/
|
|
8
|
-
import
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { builtFor, installedVersion } from './bestax-release.js';
|
|
9
|
+
import { compareVersions, isPreV1, rangeFloor } from './semver-range.js';
|
|
9
10
|
/**
|
|
10
|
-
* The
|
|
11
|
-
* 5.78.4 `Pagination.Ellipsis` keeps its class beside a `className` (#2178).
|
|
11
|
+
* The bestax-bulma release the migrated code is written for (`builtFor`).
|
|
12
12
|
* The range the manifest step adds starts there, and `bestax-floor.ts` counts
|
|
13
13
|
* on it for a package that step writes.
|
|
14
14
|
*/
|
|
15
|
-
export const BESTAX_FLOOR =
|
|
15
|
+
export const BESTAX_FLOOR = builtFor();
|
|
16
16
|
const BESTAX_RANGE = `^${BESTAX_FLOOR}`;
|
|
17
17
|
export const BULMA_RANGE = '^1.0.4';
|
|
18
18
|
/** bestax-bulma's optional peer range for Font Awesome. */
|
|
@@ -25,6 +25,7 @@ export function openManifest(filePath, pkg, collector) {
|
|
|
25
25
|
const next = pkg;
|
|
26
26
|
const report = (rule, message) => collector?.add({ file: filePath, line: null, rule, message });
|
|
27
27
|
return {
|
|
28
|
+
file: filePath,
|
|
28
29
|
next,
|
|
29
30
|
section: name => (next[name] ?? undefined),
|
|
30
31
|
note: message => {
|
|
@@ -44,10 +45,12 @@ function majorBelow(range, major) {
|
|
|
44
45
|
majors.every(found => found !== undefined && Number(found) < major));
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
* @allxsmith/bestax-bulma comes in as a runtime dependency.
|
|
48
|
-
* already
|
|
49
|
-
*
|
|
50
|
-
* the app's own step
|
|
48
|
+
* @allxsmith/bestax-bulma comes in as a runtime dependency. One the package
|
|
49
|
+
* already has, older than the release the migrated code is written for, is
|
|
50
|
+
* reported, not raised: an older major (`peer-deps`, since moving the app's
|
|
51
|
+
* existing bestax code across majors is the app's own step), and otherwise a
|
|
52
|
+
* declared range that starts below that release or an older copy the package
|
|
53
|
+
* loads (`deps`, left for the app to decide like the other reports there).
|
|
51
54
|
*/
|
|
52
55
|
export function addBestax(manifest) {
|
|
53
56
|
const dependencies = (manifest.next.dependencies ??= {});
|
|
@@ -56,9 +59,20 @@ export function addBestax(manifest) {
|
|
|
56
59
|
if (declared === undefined) {
|
|
57
60
|
dependencies['@allxsmith/bestax-bulma'] = BESTAX_RANGE;
|
|
58
61
|
manifest.note(`added @allxsmith/bestax-bulma ${BESTAX_RANGE} to dependencies`);
|
|
62
|
+
return;
|
|
59
63
|
}
|
|
60
|
-
|
|
64
|
+
if (majorBelow(declared, Number(BESTAX_FLOOR.split('.')[0]))) {
|
|
61
65
|
manifest.report('peer-deps', `@allxsmith/bestax-bulma ${declared} is older than the ${BESTAX_RANGE} the migrated code is written for; upgrade it before installing (the bestax-bulma upgrade guides cover each major)`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const floor = rangeFloor(declared);
|
|
69
|
+
if (floor !== null && compareVersions(floor, BESTAX_FLOOR) < 0) {
|
|
70
|
+
manifest.report('deps', `@allxsmith/bestax-bulma ${declared} admits releases older than the ${BESTAX_FLOOR} the migrated code is written for; raise it to start at ${BESTAX_FLOOR} or later before installing`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const installed = installedVersion(path.dirname(manifest.file));
|
|
74
|
+
if (installed && compareVersions(installed, BESTAX_FLOOR) < 0) {
|
|
75
|
+
manifest.report('deps', `this package loads @allxsmith/bestax-bulma ${installed}, older than the ${BESTAX_FLOOR} the migrated code is written for; install ${BESTAX_FLOOR} or later for it before running the migrated code`);
|
|
62
76
|
}
|
|
63
77
|
}
|
|
64
78
|
/**
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* Source-agnostic: nothing here knows which library is being migrated.
|
|
7
7
|
*/
|
|
8
8
|
import type { ASTPath, Collection, JSCodeshift } from 'jscodeshift';
|
|
9
|
-
import type {
|
|
9
|
+
import type { ComponentMapping } from '../../types.js';
|
|
10
|
+
import { type TransformContext } from './jsx-utils.js';
|
|
10
11
|
export declare const nameOf: (node: any) => string;
|
|
11
12
|
/**
|
|
12
13
|
* Every identifier the file already binds — variables, function and class
|
|
@@ -71,4 +72,52 @@ export interface AliasRegistry {
|
|
|
71
72
|
anyAlias(name: string): boolean;
|
|
72
73
|
}
|
|
73
74
|
export declare function makeAliasRegistry(): AliasRegistry;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the identifier at `path` is a name in an export specifier that
|
|
77
|
+
* binds nothing here: the public name of `export { Card as Header }`, or any
|
|
78
|
+
* name in `export … from './other'`, which names that module's exports.
|
|
79
|
+
*/
|
|
80
|
+
export declare function namesNoLocal(path: ASTPath<any>): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The locals `export { … }` names. Pruning the declaration that binds one of
|
|
83
|
+
* them (`const { Header } = Card; export { Header };`) leaves the specifier
|
|
84
|
+
* naming nothing.
|
|
85
|
+
*/
|
|
86
|
+
export declare function reExportedLocals(j: JSCodeshift, root: Collection<any>): Set<string>;
|
|
87
|
+
/**
|
|
88
|
+
* The flat bestax name a re-export of `mapping`'s component is written as
|
|
89
|
+
* (`export { Columns as Group }`), or undefined when it has none to write.
|
|
90
|
+
*/
|
|
91
|
+
export declare function flatReExportTarget(mapping: ComponentMapping | undefined): string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Why the destructuring at `path`, of the library path `base`, stays for an
|
|
94
|
+
* export, or undefined when it exports nothing as it is. A name the
|
|
95
|
+
* value-reference pass re-exports as bestax's own flat name needs no
|
|
96
|
+
* declaration, but a declaration that is the export
|
|
97
|
+
* (`export const { Header } = Card`) takes the export with it.
|
|
98
|
+
*/
|
|
99
|
+
export declare function keptForExport(path: ASTPath<any>, base: string[], reExported: Set<string>, resolveMapping: (parts: string[]) => ComponentMapping | undefined): string | undefined;
|
|
100
|
+
/** What the destructuring pass decided about its declarations. */
|
|
101
|
+
export interface DestructuringPlan {
|
|
102
|
+
/**
|
|
103
|
+
* The nodes of each kept declaration, which the value-reference pass
|
|
104
|
+
* leaves as written: the pattern's names are bindings, not references, and
|
|
105
|
+
* the initialiser names the library's root, which stays imported for it.
|
|
106
|
+
* Rewriting them as references wrote `{ Header: Card.Header }` into the
|
|
107
|
+
* pattern and pointed the initialiser at bestax's root.
|
|
108
|
+
*/
|
|
109
|
+
kept: WeakSet<object>;
|
|
110
|
+
/** Keep the declaration at `path`, destructured from `root`, with a TODO. */
|
|
111
|
+
keep(path: ASTPath<any>, root: string, message: string): void;
|
|
112
|
+
/** Prune the declaration at `path` in `settle`, unless a kept one reads it. */
|
|
113
|
+
prune(path: ASTPath<any>, root: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Keep each declaration a kept one reads (`const { Item, Bogus } = Footer`
|
|
116
|
+
* reads the one that destructures `Footer`), then prune the rest. It runs
|
|
117
|
+
* once every declaration is decided, before the scope tables change.
|
|
118
|
+
*/
|
|
119
|
+
settle(): void;
|
|
120
|
+
}
|
|
121
|
+
/** A `DestructuringPlan` for the transform whose context is `ctx`. */
|
|
122
|
+
export declare function makeDestructuringPlan(ctx: TransformContext): DestructuringPlan;
|
|
74
123
|
//# sourceMappingURL=imports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/imports.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../src/sources/_shared/imports.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIhE,eAAO,MAAM,MAAM,GAAI,MAAM,GAAG,KAAG,MACyB,CAAC;AAE7D;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,WAAW,EACd,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,gBAAgB,EAAE,MAAM,GACvB,GAAG,CAAC,MAAM,CAAC,CAmEb;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,GACjB,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAiBlC;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAQnD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAClB,IAAI,EAAE,M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