@knighted/module 1.0.0-alpha.9 → 1.0.0-beta.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.
Files changed (85) hide show
  1. package/README.md +28 -16
  2. package/dist/assignmentExpression.d.ts +12 -0
  3. package/dist/cjs/assignmentExpression.d.cts +12 -0
  4. package/dist/cjs/exports.d.cts +6 -0
  5. package/dist/cjs/expressionStatement.d.cts +2 -3
  6. package/dist/cjs/format.cjs +133 -26
  7. package/dist/cjs/format.d.cts +6 -6
  8. package/dist/cjs/formatters/assignmentExpression.cjs +37 -0
  9. package/dist/cjs/formatters/expressionStatement.cjs +36 -55
  10. package/dist/cjs/formatters/identifier.cjs +31 -31
  11. package/dist/cjs/formatters/memberExpression.cjs +24 -11
  12. package/dist/cjs/formatters/metaProperty.cjs +23 -35
  13. package/dist/cjs/helpers/identifier.cjs +132 -0
  14. package/dist/cjs/helpers/scope.cjs +12 -0
  15. package/dist/cjs/identifier.d.cts +31 -5
  16. package/dist/cjs/identifiers.d.cts +19 -0
  17. package/dist/cjs/lang.d.cts +4 -0
  18. package/dist/cjs/memberExpression.d.cts +2 -3
  19. package/dist/cjs/metaProperty.d.cts +2 -3
  20. package/dist/cjs/module.cjs +26 -27
  21. package/dist/cjs/parse.cjs +3 -14
  22. package/dist/cjs/parse.d.cts +1 -1
  23. package/dist/cjs/scope.d.cts +6 -0
  24. package/dist/cjs/types.d.cts +40 -4
  25. package/dist/cjs/url.d.cts +2 -0
  26. package/dist/cjs/utils/exports.cjs +227 -0
  27. package/dist/cjs/utils/identifiers.cjs +190 -0
  28. package/dist/cjs/utils/lang.cjs +25 -0
  29. package/dist/cjs/utils/url.cjs +16 -0
  30. package/dist/cjs/utils.cjs +288 -0
  31. package/dist/cjs/utils.d.cts +26 -0
  32. package/dist/cjs/walk.cjs +75 -0
  33. package/dist/cjs/walk.d.cts +20 -0
  34. package/dist/exports.d.ts +6 -0
  35. package/dist/expressionStatement.d.ts +2 -3
  36. package/dist/format.d.ts +6 -6
  37. package/dist/format.js +135 -27
  38. package/dist/formatters/assignmentExpression.js +30 -0
  39. package/dist/formatters/expressionStatement.js +36 -55
  40. package/dist/formatters/identifier.js +31 -31
  41. package/dist/formatters/memberExpression.js +24 -11
  42. package/dist/formatters/metaProperty.js +23 -35
  43. package/dist/helpers/identifier.js +127 -0
  44. package/dist/helpers/scope.js +7 -0
  45. package/dist/identifier.d.ts +31 -5
  46. package/dist/identifiers.d.ts +19 -0
  47. package/dist/lang.d.ts +4 -0
  48. package/dist/memberExpression.d.ts +2 -3
  49. package/dist/metaProperty.d.ts +2 -3
  50. package/dist/module.js +26 -27
  51. package/dist/parse.d.ts +1 -1
  52. package/dist/parse.js +3 -14
  53. package/dist/scope.d.ts +6 -0
  54. package/dist/src/format.d.ts +9 -0
  55. package/dist/src/formatters/assignmentExpression.d.ts +12 -0
  56. package/dist/src/formatters/expressionStatement.d.ts +4 -0
  57. package/dist/src/formatters/identifier.d.ts +12 -0
  58. package/dist/src/formatters/memberExpression.d.ts +4 -0
  59. package/dist/src/formatters/metaProperty.d.ts +4 -0
  60. package/dist/src/helpers/identifier.d.ts +31 -0
  61. package/dist/src/helpers/scope.d.ts +6 -0
  62. package/dist/src/module.d.ts +3 -0
  63. package/dist/src/parse.d.ts +2 -0
  64. package/dist/src/types.d.ts +43 -0
  65. package/dist/src/utils/exports.d.ts +6 -0
  66. package/dist/src/utils/identifiers.d.ts +19 -0
  67. package/dist/src/utils/lang.d.ts +4 -0
  68. package/dist/src/utils/url.d.ts +2 -0
  69. package/dist/src/utils.d.ts +26 -0
  70. package/dist/src/walk.d.ts +20 -0
  71. package/dist/types.d.ts +40 -4
  72. package/dist/url.d.ts +2 -0
  73. package/dist/utils/exports.js +221 -0
  74. package/dist/utils/identifiers.js +183 -0
  75. package/dist/utils/lang.js +20 -0
  76. package/dist/utils/url.js +10 -0
  77. package/dist/utils.d.ts +26 -0
  78. package/dist/utils.js +278 -0
  79. package/dist/walk.d.ts +20 -0
  80. package/dist/walk.js +69 -0
  81. package/package.json +43 -25
  82. package/dist/formatters/expressionStatement.d.ts +0 -5
  83. package/dist/formatters/identifier.d.ts +0 -5
  84. package/dist/formatters/memberExpression.d.ts +0 -5
  85. package/dist/formatters/metaProperty.d.ts +0 -5
@@ -0,0 +1,19 @@
1
+ import type { Node } from 'oxc-parser';
2
+ import type { IdentMeta, Scope } from '../types.js';
3
+ declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
4
+ /**
5
+ * Collects all module scope identifiers in the AST.
6
+ *
7
+ * Ignores identifiers that are in functions or classes.
8
+ * Ignores new scopes for StaticBlock nodes (can only reference static class members).
9
+ *
10
+ * Special case handling for these which create their own scopes,
11
+ * but are also valid module scope identifiers:
12
+ * - ClassDeclaration
13
+ * - FunctionDeclaration
14
+ *
15
+ * Special case handling for var inside BlockStatement
16
+ * which are also valid module scope identifiers.
17
+ */
18
+ declare const collectModuleIdentifiers: (ast: Node, hoisting?: boolean) => Promise<Map<string, IdentMeta>>;
19
+ export { collectScopeIdentifiers, collectModuleIdentifiers };
package/dist/lang.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Specifier } from '@knighted/specifier';
2
+ type UpdateSrcLang = Parameters<Specifier['updateSrc']>[1];
3
+ declare const getLangFromExt: (filename: string) => UpdateSrcLang;
4
+ export { getLangFromExt };
@@ -1,5 +1,4 @@
1
1
  import MagicString from 'magic-string';
2
- import type { NodePath } from '@babel/traverse';
3
- import type { MemberExpression } from '@babel/types';
2
+ import type { MemberExpression, Node } from 'oxc-parser';
4
3
  import type { FormatterOptions } from '../types.js';
5
- export declare const memberExpression: (nodePath: NodePath<MemberExpression>, src: MagicString, options: FormatterOptions) => void;
4
+ export declare const memberExpression: (node: MemberExpression, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
@@ -1,5 +1,4 @@
1
1
  import MagicString from 'magic-string';
2
- import type { NodePath } from '@babel/traverse';
3
- import type { MetaProperty } from '@babel/types';
2
+ import type { Node, MetaProperty } from 'oxc-parser';
4
3
  import type { FormatterOptions } from '../types.js';
5
- export declare const metaProperty: (nodePath: NodePath<MetaProperty>, src: MagicString, options: FormatterOptions) => void;
4
+ export declare const metaProperty: (node: MetaProperty, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
package/dist/module.js CHANGED
@@ -1,28 +1,22 @@
1
- import { resolve, extname } from 'node:path';
1
+ import { resolve } from 'node:path';
2
2
  import { readFile, writeFile } from 'node:fs/promises';
3
3
  import { specifier } from '@knighted/specifier';
4
- import { parse } from './parse.js';
5
- import { format } from './format.js';
4
+ import { parse } from '#parse';
5
+ import { format } from '#format';
6
+ import { getLangFromExt } from '#utils/lang.js';
6
7
  const defaultOptions = {
7
- type: 'commonjs',
8
+ target: 'commonjs',
9
+ sourceType: 'auto',
10
+ transformSyntax: true,
11
+ liveBindings: 'strict',
12
+ rewriteSpecifier: undefined,
13
+ dirFilename: 'inject',
14
+ importMeta: 'shim',
15
+ requireSource: 'builtin',
16
+ cjsDefault: 'auto',
17
+ topLevelAwait: 'error',
8
18
  out: undefined,
9
- modules: false,
10
- specifier: undefined
11
- };
12
- const getLangFromExt = filename => {
13
- const ext = extname(filename);
14
- if (/\.js$/.test(ext)) {
15
- return 'js';
16
- }
17
- if (/\.ts$/.test(ext)) {
18
- return 'ts';
19
- }
20
- if (ext === '.tsx') {
21
- return 'tsx';
22
- }
23
- if (ext === '.jsx') {
24
- return 'jsx';
25
- }
19
+ inPlace: false
26
20
  };
27
21
  const transform = async (filename, options = defaultOptions) => {
28
22
  const opts = {
@@ -31,24 +25,29 @@ const transform = async (filename, options = defaultOptions) => {
31
25
  };
32
26
  const file = resolve(filename);
33
27
  const code = (await readFile(file)).toString();
34
- const ast = parse(code);
35
- let source = format(code, ast, opts).toString();
36
- if (options.specifier) {
28
+ const ast = parse(filename, code);
29
+ let source = await format(code, ast, opts);
30
+ if (opts.rewriteSpecifier) {
37
31
  const code = await specifier.updateSrc(source, getLangFromExt(filename), ({
38
32
  value
39
33
  }) => {
34
+ if (typeof opts.rewriteSpecifier === 'function') {
35
+ return opts.rewriteSpecifier(value) ?? undefined;
36
+ }
37
+
40
38
  // Collapse any BinaryExpression or NewExpression to test for a relative specifier
41
39
  const collapsed = value.replace(/['"`+)\s]|new String\(/g, '');
42
40
  const relative = /^(?:\.|\.\.)\//;
43
41
  if (relative.test(collapsed)) {
44
42
  // $2 is for any closing quotation/parens around BE or NE
45
- return value.replace(/(.+)\.(?:m|c)?(?:j|t)s([)'"`]*)?$/, `$1${options.specifier}$2`);
43
+ return value.replace(/(.+)\.(?:m|c)?(?:j|t)s([)'"]*)?$/, `$1${opts.rewriteSpecifier}$2`);
46
44
  }
47
45
  });
48
46
  source = code;
49
47
  }
50
- if (opts.out) {
51
- await writeFile(resolve(opts.out), source);
48
+ const outputPath = opts.inPlace ? file : opts.out ? resolve(opts.out) : undefined;
49
+ if (outputPath) {
50
+ await writeFile(outputPath, source);
52
51
  }
53
52
  return source;
54
53
  };
package/dist/parse.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const parse: (source: string, dts?: boolean) => import("@babel/parser").ParseResult<import("@babel/types").File>;
1
+ declare const parse: (filename: string, code: string) => import("oxc-parser").ParseResult;
2
2
  export { parse };
package/dist/parse.js CHANGED
@@ -1,16 +1,5 @@
1
- import { parse as babelParse } from '@babel/parser';
2
- const parse = (source, dts = false) => {
3
- const ast = babelParse(source, {
4
- sourceType: 'module',
5
- allowAwaitOutsideFunction: true,
6
- allowReturnOutsideFunction: true,
7
- allowImportExportEverywhere: true,
8
- plugins: ['jsx', ['importAttributes', {
9
- deprecatedAssertSyntax: true
10
- }], ['typescript', {
11
- dts
12
- }]]
13
- });
14
- return ast;
1
+ import { parseSync } from 'oxc-parser';
2
+ const parse = (filename, code) => {
3
+ return parseSync(filename, code);
15
4
  };
16
5
  export { parse };
@@ -0,0 +1,6 @@
1
+ import type { Node } from 'oxc-parser';
2
+ declare const scopes: string[];
3
+ declare const scope: {
4
+ isScope(node: Node): boolean;
5
+ };
6
+ export { scopes, scope };
@@ -0,0 +1,9 @@
1
+ import type { ParseResult } from 'oxc-parser';
2
+ import type { FormatterOptions } from './types.js';
3
+ /**
4
+ * Node added support for import.meta.main.
5
+ * Added in: v24.2.0, v22.18.0
6
+ * @see https://nodejs.org/api/esm.html#importmetamain
7
+ */
8
+ declare const format: (src: string, ast: ParseResult, opts: FormatterOptions) => Promise<string>;
9
+ export { format };
@@ -0,0 +1,12 @@
1
+ import MagicString from 'magic-string';
2
+ import type { Node, AssignmentExpression } from 'oxc-parser';
3
+ import type { FormatterOptions, ExportsMeta } from '../types.js';
4
+ type AssignmentExpressionArg = {
5
+ node: AssignmentExpression;
6
+ parent: Node | null;
7
+ code: MagicString;
8
+ opts: FormatterOptions;
9
+ meta: ExportsMeta;
10
+ };
11
+ export declare const assignmentExpression: ({ node, parent: _parent, code: _code, opts, meta: _meta, }: AssignmentExpressionArg) => Promise<void>;
12
+ export {};
@@ -0,0 +1,4 @@
1
+ import MagicString from 'magic-string';
2
+ import type { Node, ExpressionStatement } from 'oxc-parser';
3
+ import type { FormatterOptions } from '../types.js';
4
+ export declare const expressionStatement: (node: ExpressionStatement, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
@@ -0,0 +1,12 @@
1
+ import MagicString from 'magic-string';
2
+ import type { Node, IdentifierName } from 'oxc-parser';
3
+ import type { FormatterOptions, ExportsMeta } from '../types.js';
4
+ type IdentifierArg = {
5
+ node: IdentifierName;
6
+ ancestors: Node[];
7
+ code: MagicString;
8
+ opts: FormatterOptions;
9
+ meta: ExportsMeta;
10
+ };
11
+ export declare const identifier: ({ node, ancestors, code, opts, meta }: IdentifierArg) => void;
12
+ export {};
@@ -0,0 +1,4 @@
1
+ import MagicString from 'magic-string';
2
+ import type { MemberExpression, Node } from 'oxc-parser';
3
+ import type { FormatterOptions } from '../types.js';
4
+ export declare const memberExpression: (node: MemberExpression, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
@@ -0,0 +1,4 @@
1
+ import MagicString from 'magic-string';
2
+ import type { Node, MetaProperty } from 'oxc-parser';
3
+ import type { FormatterOptions } from '../types.js';
4
+ export declare const metaProperty: (node: MetaProperty, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
@@ -0,0 +1,31 @@
1
+ import type { Node, IdentifierName } from 'oxc-parser';
2
+ /**
3
+ * Focus exclusively on IdentifierName type as it has the name property,
4
+ * which is what the identifer utilities are interested in.
5
+ *
6
+ * Explicitly ignore the TSThisParameter type as it is not a valid identifier name.
7
+ */
8
+ declare const isIdentifierName: (node: Node) => node is IdentifierName;
9
+ /**
10
+ * All methods receive the full set of ancestors, which
11
+ * specifically includes the node itself as the last element.
12
+ * The second to last element is the parent node, and so on.
13
+ * The first element is the root node.
14
+ */
15
+ declare const identifier: {
16
+ isNamed: (node: Node) => node is IdentifierName;
17
+ isMetaProperty(ancestors: Node[]): boolean;
18
+ isModuleScope(ancestors: Node[], includeImports?: boolean): boolean;
19
+ isMemberExpressionRoot(ancestors: Node[]): boolean;
20
+ isDeclaration(ancestors: Node[]): boolean;
21
+ isClassOrFuncDeclarationId(ancestors: Node[]): boolean;
22
+ isVarDeclarationInGlobalScope(ancestors: Node[]): boolean;
23
+ isIife(ancestors: Node[]): boolean;
24
+ isFunctionExpressionId(ancestors: Node[]): boolean;
25
+ isExportSpecifierAlias(ancestors: Node[]): boolean;
26
+ isClassPropertyKey(ancestors: Node[]): boolean;
27
+ isMethodDefinitionKey(ancestors: Node[]): boolean;
28
+ isMemberKey(ancestors: Node[]): boolean;
29
+ isPropertyKey(ancestors: Node[]): boolean;
30
+ };
31
+ export { identifier, isIdentifierName };
@@ -0,0 +1,6 @@
1
+ import type { Node } from 'oxc-parser';
2
+ declare const scopes: string[];
3
+ declare const scope: {
4
+ isScope(node: Node): boolean;
5
+ };
6
+ export { scopes, scope };
@@ -0,0 +1,3 @@
1
+ import type { ModuleOptions } from './types.js';
2
+ declare const transform: (filename: string, options?: ModuleOptions) => Promise<string>;
3
+ export { transform };
@@ -0,0 +1,2 @@
1
+ declare const parse: (filename: string, code: string) => import("oxc-parser").ParseResult;
2
+ export { parse };
@@ -0,0 +1,43 @@
1
+ import type { Node, Span, IdentifierName, IdentifierReference, BindingIdentifier, LabelIdentifier, TSIndexSignatureName } from 'oxc-parser';
2
+ export type RewriteSpecifier = '.js' | '.mjs' | '.cjs' | '.ts' | '.mts' | '.cts' | ((value: string) => string | null | undefined);
3
+ export type ModuleOptions = {
4
+ target: 'module' | 'commonjs';
5
+ sourceType?: 'auto' | 'module' | 'commonjs';
6
+ transformSyntax?: boolean;
7
+ liveBindings?: 'strict' | 'loose' | 'off';
8
+ rewriteSpecifier?: RewriteSpecifier;
9
+ dirFilename?: 'inject' | 'preserve' | 'error';
10
+ importMeta?: 'preserve' | 'shim' | 'error';
11
+ requireSource?: 'builtin' | 'create-require';
12
+ cjsDefault?: 'module-exports' | 'auto' | 'none';
13
+ topLevelAwait?: 'error' | 'wrap' | 'preserve';
14
+ out?: string;
15
+ inPlace?: boolean;
16
+ };
17
+ export type SpannedNode = Node & Span;
18
+ export type ExportsMeta = {
19
+ hasExportsBeenReassigned: boolean;
20
+ hasDefaultExportBeenReassigned: boolean;
21
+ hasDefaultExportBeenAssigned: boolean;
22
+ defaultExportValue: unknown;
23
+ };
24
+ export type CjsExport = {
25
+ key: string;
26
+ writes: SpannedNode[];
27
+ fromIdentifier?: string;
28
+ via: Set<'exports' | 'module.exports'>;
29
+ reassignments: SpannedNode[];
30
+ hasGetter?: boolean;
31
+ };
32
+ export type IdentMeta = {
33
+ declare: SpannedNode[];
34
+ read: SpannedNode[];
35
+ };
36
+ export type Scope = {
37
+ type: string;
38
+ name: string;
39
+ node: Node;
40
+ idents: Set<string>;
41
+ };
42
+ export type FormatterOptions = Omit<ModuleOptions, 'out' | 'inPlace'>;
43
+ export type Identifier = IdentifierName | IdentifierReference | BindingIdentifier | LabelIdentifier | TSIndexSignatureName;
@@ -0,0 +1,6 @@
1
+ import type { Node } from 'oxc-parser';
2
+ import type { CjsExport } from '../types.js';
3
+ declare const exportsRename = "__exports";
4
+ declare const requireMainRgx: RegExp;
5
+ declare const collectCjsExports: (ast: Node) => Promise<Map<string, CjsExport>>;
6
+ export { exportsRename, requireMainRgx, collectCjsExports };
@@ -0,0 +1,19 @@
1
+ import type { Node } from 'oxc-parser';
2
+ import type { IdentMeta, Scope } from '../types.js';
3
+ declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
4
+ /**
5
+ * Collects all module scope identifiers in the AST.
6
+ *
7
+ * Ignores identifiers that are in functions or classes.
8
+ * Ignores new scopes for StaticBlock nodes (can only reference static class members).
9
+ *
10
+ * Special case handling for these which create their own scopes,
11
+ * but are also valid module scope identifiers:
12
+ * - ClassDeclaration
13
+ * - FunctionDeclaration
14
+ *
15
+ * Special case handling for var inside BlockStatement
16
+ * which are also valid module scope identifiers.
17
+ */
18
+ declare const collectModuleIdentifiers: (ast: Node, hoisting?: boolean) => Promise<Map<string, IdentMeta>>;
19
+ export { collectScopeIdentifiers, collectModuleIdentifiers };
@@ -0,0 +1,4 @@
1
+ import type { Specifier } from '@knighted/specifier';
2
+ type UpdateSrcLang = Parameters<Specifier['updateSrc']>[1];
3
+ declare const getLangFromExt: (filename: string) => UpdateSrcLang;
4
+ export { getLangFromExt };
@@ -0,0 +1,2 @@
1
+ declare const isValidUrl: (url: string) => boolean;
2
+ export { isValidUrl };
@@ -0,0 +1,26 @@
1
+ import type { Node } from 'oxc-parser';
2
+ import type { Specifier } from '@knighted/specifier';
3
+ import type { IdentMeta, Scope, CjsExport } from './types.js';
4
+ type UpdateSrcLang = Parameters<Specifier['updateSrc']>[1];
5
+ declare const getLangFromExt: (filename: string) => UpdateSrcLang;
6
+ declare const isValidUrl: (url: string) => boolean;
7
+ declare const exportsRename = "__exports";
8
+ declare const requireMainRgx: RegExp;
9
+ declare const collectCjsExports: (ast: Node) => Promise<Map<string, CjsExport>>;
10
+ declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
11
+ /**
12
+ * Collects all module scope identifiers in the AST.
13
+ *
14
+ * Ignores identifiers that are in functions or classes.
15
+ * Ignores new scopes for StaticBlock nodes (can only reference static class members).
16
+ *
17
+ * Special case handling for these which create their own scopes,
18
+ * but are also valid module scope identifiers:
19
+ * - ClassDeclaration
20
+ * - FunctionDeclaration
21
+ *
22
+ * Special case handling for var inside BlockStatement
23
+ * which are also valid module scope identifiers.
24
+ */
25
+ declare const collectModuleIdentifiers: (ast: Node, hoisting?: boolean) => Promise<Map<string, IdentMeta>>;
26
+ export { getLangFromExt, isValidUrl, collectScopeIdentifiers, collectModuleIdentifiers, collectCjsExports, exportsRename, requireMainRgx, };
@@ -0,0 +1,20 @@
1
+ import type { Node } from 'oxc-parser';
2
+ /**
3
+ * Using visitorKeys instead of oxc Visitor to keep
4
+ * an ancestor-aware enter/leave API with this.skip()
5
+ * without per-node method boilerplate.
6
+ */
7
+ type AncestorContext = {
8
+ skip: () => void;
9
+ };
10
+ type AncestorVisitor = {
11
+ enter?: (this: AncestorContext, node: Node, ancestors: Node[]) => void | Promise<void>;
12
+ leave?: (this: AncestorContext, node: Node, ancestors: Node[]) => void | Promise<void>;
13
+ };
14
+ type WalkVisitor = {
15
+ enter?: (this: AncestorContext, node: Node, parent: Node | null) => void | Promise<void>;
16
+ leave?: (this: AncestorContext, node: Node, parent: Node | null) => void | Promise<void>;
17
+ };
18
+ declare const ancestorWalk: (node: Node, visitors: AncestorVisitor) => Promise<void>;
19
+ declare const walk: (node: Node, visitors: WalkVisitor) => Promise<void>;
20
+ export { ancestorWalk, walk };
package/dist/types.d.ts CHANGED
@@ -1,7 +1,43 @@
1
+ import type { Node, Span, IdentifierName, IdentifierReference, BindingIdentifier, LabelIdentifier, TSIndexSignatureName } from 'oxc-parser';
2
+ export type RewriteSpecifier = '.js' | '.mjs' | '.cjs' | '.ts' | '.mts' | '.cts' | ((value: string) => string | null | undefined);
1
3
  export type ModuleOptions = {
2
- type?: 'module' | 'commonjs';
3
- modules?: boolean;
4
- specifier?: '.js' | '.mjs' | '.cjs' | '.ts' | '.mts' | '.cts';
4
+ target: 'module' | 'commonjs';
5
+ sourceType?: 'auto' | 'module' | 'commonjs';
6
+ transformSyntax?: boolean;
7
+ liveBindings?: 'strict' | 'loose' | 'off';
8
+ rewriteSpecifier?: RewriteSpecifier;
9
+ dirFilename?: 'inject' | 'preserve' | 'error';
10
+ importMeta?: 'preserve' | 'shim' | 'error';
11
+ requireSource?: 'builtin' | 'create-require';
12
+ cjsDefault?: 'module-exports' | 'auto' | 'none';
13
+ topLevelAwait?: 'error' | 'wrap' | 'preserve';
5
14
  out?: string;
15
+ inPlace?: boolean;
6
16
  };
7
- export type FormatterOptions = Omit<ModuleOptions, 'out'> & Required<Pick<ModuleOptions, 'type'>>;
17
+ export type SpannedNode = Node & Span;
18
+ export type ExportsMeta = {
19
+ hasExportsBeenReassigned: boolean;
20
+ hasDefaultExportBeenReassigned: boolean;
21
+ hasDefaultExportBeenAssigned: boolean;
22
+ defaultExportValue: unknown;
23
+ };
24
+ export type CjsExport = {
25
+ key: string;
26
+ writes: SpannedNode[];
27
+ fromIdentifier?: string;
28
+ via: Set<'exports' | 'module.exports'>;
29
+ reassignments: SpannedNode[];
30
+ hasGetter?: boolean;
31
+ };
32
+ export type IdentMeta = {
33
+ declare: SpannedNode[];
34
+ read: SpannedNode[];
35
+ };
36
+ export type Scope = {
37
+ type: string;
38
+ name: string;
39
+ node: Node;
40
+ idents: Set<string>;
41
+ };
42
+ export type FormatterOptions = Omit<ModuleOptions, 'out' | 'inPlace'>;
43
+ export type Identifier = IdentifierName | IdentifierReference | BindingIdentifier | LabelIdentifier | TSIndexSignatureName;
package/dist/url.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const isValidUrl: (url: string) => boolean;
2
+ export { isValidUrl };