Skip to content

Commit

Permalink
refactor(utils): [findExports] sort statements by start location
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Mar 3, 2023
1 parent ffa130c commit 7926a01
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
76 changes: 38 additions & 38 deletions src/utils/__snapshots__/find-exports.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/find-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7926a01

Please sign in to comment.