From 7926a010729d99d109df475068703b22e7073920 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Thu, 2 Mar 2023 23:53:45 -0500 Subject: [PATCH] refactor(utils): [`findExports`] sort statements by `start` location Signed-off-by: Lexus Drumgold --- src/utils/__snapshots__/find-exports.snap | 76 +++++++++++------------ src/utils/find-exports.ts | 4 +- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/utils/__snapshots__/find-exports.snap b/src/utils/__snapshots__/find-exports.snap index 4b417304..2714439e 100644 --- a/src/utils/__snapshots__/find-exports.snap +++ b/src/utils/__snapshots__/find-exports.snap @@ -2,6 +2,28 @@ exports[`unit:utils/findExports > should return ExportStatement object array 1`] = ` [ + { + "code": "export { + DEFAULTS, + plugin as default, + type Options +}", + "declaration": null, + "end": 58, + "exports": [ + "DEFAULTS", + "plugin as default", + "type Options", + ], + "kind": "export", + "modifiers": [], + "specifier": null, + "specifier_kind": null, + "specifier_syntax": null, + "start": 0, + "syntax": "list", + "type": false, + }, { "code": "export { defineBuildConfig, type BuildConfig } from \\"#src\\"", "declaration": null, @@ -89,6 +111,22 @@ exports[`unit:utils/findExports > should return ExportStatement object array 1`] "syntax": "namespace", "type": false, }, + { + "code": "export type { default as Options }", + "declaration": null, + "end": 405, + "exports": [ + "default as Options", + ], + "kind": "export", + "modifiers": [], + "specifier": null, + "specifier_kind": null, + "specifier_syntax": null, + "start": 371, + "syntax": "list", + "type": true, + }, { "code": "export type { default as Options } from \\"./options\\"", "declaration": null, @@ -237,44 +275,6 @@ exports[`unit:utils/findExports > should return ExportStatement object array 1`] "syntax": "default", "type": false, }, - { - "code": "export { - DEFAULTS, - plugin as default, - type Options -}", - "declaration": null, - "end": 58, - "exports": [ - "DEFAULTS", - "plugin as default", - "type Options", - ], - "kind": "export", - "modifiers": [], - "specifier": null, - "specifier_kind": null, - "specifier_syntax": null, - "start": 0, - "syntax": "list", - "type": false, - }, - { - "code": "export type { default as Options }", - "declaration": null, - "end": 405, - "exports": [ - "default as Options", - ], - "kind": "export", - "modifiers": [], - "specifier": null, - "specifier_kind": null, - "specifier_syntax": null, - "start": 371, - "syntax": "list", - "type": true, - }, { "code": "export type { Config, Result }", "declaration": null, diff --git a/src/utils/find-exports.ts b/src/utils/find-exports.ts index 866ffb99..ab7a1f9c 100644 --- a/src/utils/find-exports.ts +++ b/src/utils/find-exports.ts @@ -158,7 +158,9 @@ const findExports = (code: string = ''): ExportStatement[] => { }) } - return statements + return statements.sort((s1: ExportStatement, s2: ExportStatement): number => { + return s1.start - s2.start + }) } export default findExports