@platformos/platformos-graph 0.0.20 → 0.2.0
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/CHANGELOG.md +622 -8
- package/dist/cache-probes.spec.d.ts +1 -0
- package/dist/cache-probes.spec.js +62 -0
- package/dist/cache-probes.spec.js.map +1 -0
- package/dist/cli.js +18 -13
- package/dist/cli.js.map +1 -1
- package/dist/cli.spec.d.ts +1 -0
- package/dist/cli.spec.js +235 -0
- package/dist/cli.spec.js.map +1 -0
- package/dist/graph/app-index-resolution.spec.d.ts +1 -0
- package/dist/graph/app-index-resolution.spec.js +167 -0
- package/dist/graph/app-index-resolution.spec.js.map +1 -0
- package/dist/graph/asset-resolution.spec.d.ts +1 -0
- package/dist/graph/asset-resolution.spec.js +64 -0
- package/dist/graph/asset-resolution.spec.js.map +1 -0
- package/dist/graph/augment.js +3 -0
- package/dist/graph/augment.js.map +1 -1
- package/dist/graph/build.d.ts +15 -2
- package/dist/graph/build.js +54 -12
- package/dist/graph/build.js.map +1 -1
- package/dist/graph/build.spec.d.ts +1 -0
- package/dist/graph/build.spec.js +138 -0
- package/dist/graph/build.spec.js.map +1 -0
- package/dist/graph/edge-sources.d.ts +28 -0
- package/dist/graph/edge-sources.js +43 -0
- package/dist/graph/edge-sources.js.map +1 -0
- package/dist/graph/edge-sources.spec.d.ts +1 -0
- package/dist/graph/edge-sources.spec.js +125 -0
- package/dist/graph/edge-sources.spec.js.map +1 -0
- package/dist/graph/extract.spec.d.ts +1 -0
- package/dist/graph/extract.spec.js +163 -0
- package/dist/graph/extract.spec.js.map +1 -0
- package/dist/graph/module.d.ts +60 -7
- package/dist/graph/module.js +137 -41
- package/dist/graph/module.js.map +1 -1
- package/dist/graph/module.spec.d.ts +1 -0
- package/dist/graph/module.spec.js +74 -0
- package/dist/graph/module.spec.js.map +1 -0
- package/dist/graph/query.d.ts +72 -0
- package/dist/graph/query.js +140 -0
- package/dist/graph/query.js.map +1 -0
- package/dist/graph/query.spec.d.ts +1 -0
- package/dist/graph/query.spec.js +209 -0
- package/dist/graph/query.spec.js.map +1 -0
- package/dist/graph/serialize.spec.d.ts +1 -0
- package/dist/graph/serialize.spec.js +50 -0
- package/dist/graph/serialize.spec.js.map +1 -0
- package/dist/graph/structural.spec.d.ts +1 -0
- package/dist/graph/structural.spec.js +146 -0
- package/dist/graph/structural.spec.js.map +1 -0
- package/dist/graph/test-helpers.js +3 -3
- package/dist/graph/test-helpers.js.map +1 -1
- package/dist/graph/traverse-edges.spec.d.ts +1 -0
- package/dist/graph/traverse-edges.spec.js +337 -0
- package/dist/graph/traverse-edges.spec.js.map +1 -0
- package/dist/graph/traverse.d.ts +51 -20
- package/dist/graph/traverse.js +239 -29
- package/dist/graph/traverse.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/parsers.d.ts +35 -0
- package/dist/parsers.js +72 -0
- package/dist/parsers.js.map +1 -0
- package/dist/parsers.spec.d.ts +1 -0
- package/dist/parsers.spec.js +70 -0
- package/dist/parsers.spec.js.map +1 -0
- package/dist/toSourceCode.d.ts +14 -2
- package/dist/toSourceCode.js +23 -19
- package/dist/toSourceCode.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +107 -3
- package/dist/types.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/fixtures/asset-edges/app/assets/logo.css +1 -0
- package/fixtures/asset-edges/app/assets/site/app.js +1 -0
- package/fixtures/asset-edges/app/views/pages/index.liquid +3 -0
- package/fixtures/graphql-table/app/graphql/remote_table.graphql +9 -0
- package/fixtures/graphql-table/app/graphql/table_as_argument.graphql +5 -0
- package/fixtures/graphql-table/app/graphql/with_table.graphql +5 -0
- package/fixtures/graphql-table/app/graphql/without_table.graphql +3 -0
- package/fixtures/graphql-table/app/views/pages/index.liquid +6 -0
- package/fixtures/layout-edges/app/views/layouts/theme.liquid +4 -0
- package/fixtures/layout-edges/app/views/pages/broken.liquid +5 -0
- package/fixtures/layout-edges/app/views/pages/index.liquid +5 -0
- package/fixtures/schema-nodes/app/schema/blog_post.yml +6 -0
- package/fixtures/schema-nodes/app/schema/no_name.yml +3 -0
- package/fixtures/schema-nodes/app/views/pages/index.liquid +1 -0
- package/fixtures/structural/app/views/pages/about.liquid +1 -0
- package/fixtures/structural/app/views/pages/blog/show.liquid +4 -0
- package/fixtures/structural/app/views/pages/index.liquid +6 -0
- package/fixtures/structural/app/views/pages/rich.liquid +8 -0
- package/fixtures/structural/app/views/partials/card.liquid +1 -0
- package/fixtures/structural/app/views/partials/documented.liquid +5 -0
- package/package.json +7 -5
- package/src/cli.spec.ts +37 -31
- package/src/cli.ts +31 -15
- package/src/graph/augment.ts +4 -0
- package/src/graph/build.spec.ts +891 -6
- package/src/graph/build.ts +68 -17
- package/src/graph/edge-sources.spec.ts +125 -0
- package/src/graph/edge-sources.ts +49 -0
- package/src/graph/module.spec.ts +168 -0
- package/src/graph/module.ts +139 -45
- package/src/graph/query.spec.ts +260 -0
- package/src/graph/query.ts +154 -0
- package/src/graph/serialize.spec.ts +4 -4
- package/src/graph/test-helpers.ts +3 -3
- package/src/graph/{extract.spec.ts → traverse.spec.ts} +125 -2
- package/src/graph/traverse.ts +278 -37
- package/src/index.ts +16 -1
- package/src/parsers.spec.ts +85 -0
- package/src/parsers.ts +75 -0
- package/src/toSourceCode.ts +26 -26
- package/src/types.ts +111 -7
- package/src/utils/index.ts +1 -1
- package/dist/getWebComponentMap.d.ts +0 -10
- package/dist/getWebComponentMap.js +0 -66
- package/dist/getWebComponentMap.js.map +0 -1
- package/src/graph/traverse-edges.spec.ts +0 -278
- /package/fixtures/skeleton/{assets → app/assets}/app.css +0 -0
- /package/fixtures/skeleton/{assets → app/assets}/app.js +0 -0
package/dist/parsers.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.graphParsers = void 0;
|
|
4
|
+
exports.parseJs = parseJs;
|
|
5
|
+
exports.appBackedGetSourceCode = appBackedGetSourceCode;
|
|
6
|
+
const platformos_check_common_1 = require("@platformos/platformos-check-common");
|
|
7
|
+
const acorn_1 = require("acorn");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
/** Parse a JavaScript asset, capturing a syntax error as a value rather than throwing. */
|
|
10
|
+
function parseJs(source) {
|
|
11
|
+
try {
|
|
12
|
+
return (0, acorn_1.parse)(source, {
|
|
13
|
+
ecmaVersion: 'latest',
|
|
14
|
+
sourceType: 'module',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return (0, platformos_check_common_1.asError)(error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A binary asset has nothing to parse. It is still a graph node — something links
|
|
23
|
+
* to it — so it gets an `Error` value rather than being absent, exactly as an
|
|
24
|
+
* unparseable file would.
|
|
25
|
+
*/
|
|
26
|
+
const parseOpaqueAsset = () => new Error('File parsing not implemented');
|
|
27
|
+
/**
|
|
28
|
+
* The file types the GRAPH holds and the linter does not: `.js` assets and images.
|
|
29
|
+
*
|
|
30
|
+
* They exist for {@link toSourceCode}'s contract — every URI it is handed comes back as a
|
|
31
|
+
* `FileSourceCode` — and so an `App` an asset URI is put into can answer `ast` at all. NOT
|
|
32
|
+
* because a graph build reads them: `traverseModule` returns immediately for an Asset node, and
|
|
33
|
+
* the only question the graph asks about an asset is whether it EXISTS.
|
|
34
|
+
*
|
|
35
|
+
* Registering them on an {@link App} — rather than building a second set of file objects — is
|
|
36
|
+
* what lets a graph build and a lint run over the same project hold the SAME `AppFile`
|
|
37
|
+
* instances, so each file is read and parsed at most once for both. The language server does
|
|
38
|
+
* that; check-node builds no graph, so merging into `nodeParsers` would do nothing.
|
|
39
|
+
*
|
|
40
|
+
* THE MCP SUPERVISOR DELIBERATELY DOES NOT SHARE, and this is not a pending to-do: it builds no
|
|
41
|
+
* graph, parsing per request only the handful of files that could reference the edited one.
|
|
42
|
+
* Routing those through check-node's shared `App` would win nothing — `lintBuffers` parses the
|
|
43
|
+
* content it was HANDED and drops the app's entry on the way out — and would risk something,
|
|
44
|
+
* because that `App` carries UNSAVED buffers while its impact stage runs CONCURRENTLY with
|
|
45
|
+
* the lint.
|
|
46
|
+
*/
|
|
47
|
+
exports.graphParsers = {
|
|
48
|
+
extensions: {
|
|
49
|
+
js: parseJs,
|
|
50
|
+
...Object.fromEntries(types_1.SUPPORTED_ASSET_IMAGE_EXTENSIONS.map((extension) => [extension, parseOpaqueAsset])),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A `getSourceCode` for the graph backed by an {@link App}.
|
|
55
|
+
*
|
|
56
|
+
* Pass it as `IDependencies.getSourceCode` and the graph stops parsing anything the
|
|
57
|
+
* lint has already parsed, and vice versa — they read the same file objects. Files
|
|
58
|
+
* the app does not contain fall through to `fallback`, which is how a URI outside
|
|
59
|
+
* the project (or an unclassified file) still gets a source code.
|
|
60
|
+
*/
|
|
61
|
+
function appBackedGetSourceCode(app, fallback) {
|
|
62
|
+
return async (uri) => {
|
|
63
|
+
const file = app.get(uri);
|
|
64
|
+
if (!file)
|
|
65
|
+
return fallback(uri);
|
|
66
|
+
await file.load();
|
|
67
|
+
// An AppFile is structurally a SourceCode; its `ast` is typed `unknown` only
|
|
68
|
+
// because platformos-common sits below the parsers that produce ASTs.
|
|
69
|
+
return file;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../src/parsers.ts"],"names":[],"mappings":";;;AAOA,0BASC;AA8CD,wDAYC;AAzED,iFAA8D;AAC9D,iCAAqD;AAErD,mCAA2E;AAE3E,0FAA0F;AAC1F,SAAgB,OAAO,CAAC,MAAc;IACpC,IAAI,CAAC;QACH,OAAO,IAAA,aAAU,EAAC,MAAM,EAAE;YACxB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,QAAQ;SACrB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAA,iCAAO,EAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,gBAAgB,GAAW,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;GAmBG;AACU,QAAA,YAAY,GAAY;IACnC,UAAU,EAAE;QACV,EAAE,EAAE,OAAO;QACX,GAAG,MAAM,CAAC,WAAW,CACnB,wCAAgC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CACnF;KACF;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,GAAQ,EACR,QAAqD;IAErD,OAAO,KAAK,EAAE,GAAc,EAA2B,EAAE;QACvD,MAAM,IAAI,GAAwB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI;YAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,6EAA6E;QAC7E,sEAAsE;QACtE,OAAO,IAAiC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const platformos_common_1 = require("@platformos/platformos-common");
|
|
4
|
+
const platformos_check_common_1 = require("@platformos/platformos-check-common");
|
|
5
|
+
const vitest_1 = require("vitest");
|
|
6
|
+
const parsers_1 = require("./parsers");
|
|
7
|
+
const toSourceCode_1 = require("./toSourceCode");
|
|
8
|
+
const ROOT = 'file:///project';
|
|
9
|
+
const uri = (relativePath) => `${ROOT}/${relativePath}`;
|
|
10
|
+
const fsOver = (files) => ({
|
|
11
|
+
readFile: async (target) => {
|
|
12
|
+
const source = files[target];
|
|
13
|
+
if (source === undefined)
|
|
14
|
+
throw new Error(`ENOENT: ${target}`);
|
|
15
|
+
return source;
|
|
16
|
+
},
|
|
17
|
+
stat: async () => {
|
|
18
|
+
throw new Error('not used');
|
|
19
|
+
},
|
|
20
|
+
readDirectory: async () => [],
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.describe)('graphParsers', () => {
|
|
23
|
+
(0, vitest_1.it)('registers a JS parser and treats images as opaque', async () => {
|
|
24
|
+
const jsUri = uri('app/assets/app.js');
|
|
25
|
+
const pngUri = uri('app/assets/logo.png');
|
|
26
|
+
const files = { [jsUri]: 'export const a = 1;', [pngUri]: 'binary' };
|
|
27
|
+
const app = platformos_common_1.App.fromPaths(ROOT, [jsUri, pngUri], fsOver(files), parsers_1.graphParsers);
|
|
28
|
+
await app.load();
|
|
29
|
+
(0, vitest_1.expect)(app.get(jsUri).ast.type).toBe('Program');
|
|
30
|
+
(0, vitest_1.expect)(app.get(pngUri).ast).toEqual(new Error('File parsing not implemented'));
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('is the same JS parse the buffer path uses', async () => {
|
|
33
|
+
const source = 'export const a = 1;';
|
|
34
|
+
const jsUri = uri('app/assets/app.js');
|
|
35
|
+
const app = platformos_common_1.App.fromPaths(ROOT, [jsUri], fsOver({ [jsUri]: source }), parsers_1.graphParsers);
|
|
36
|
+
await app.load();
|
|
37
|
+
const fromBuffer = await (0, toSourceCode_1.toSourceCode)(jsUri, source);
|
|
38
|
+
(0, vitest_1.expect)(app.get(jsUri).ast).toEqual(fromBuffer.ast);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.describe)('appBackedGetSourceCode', () => {
|
|
42
|
+
const parsers = (liquid = vitest_1.vi.fn(platformos_check_common_1.toLiquidHTMLAST)) => ({
|
|
43
|
+
parsers: { [platformos_common_1.SourceCodeType.LiquidHtml]: liquid, extensions: parsers_1.graphParsers.extensions },
|
|
44
|
+
liquid,
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('parses a file at most once across a graph read and a lint read', async () => {
|
|
47
|
+
const cardUri = uri('app/views/partials/card.liquid');
|
|
48
|
+
const { parsers: registered, liquid } = parsers();
|
|
49
|
+
const app = platformos_common_1.App.fromPaths(ROOT, [cardUri], fsOver({ [cardUri]: '<b>card</b>' }), registered);
|
|
50
|
+
const getSourceCode = (0, parsers_1.appBackedGetSourceCode)(app, async () => {
|
|
51
|
+
throw new Error('fallback should not be needed');
|
|
52
|
+
});
|
|
53
|
+
// The graph asks for it…
|
|
54
|
+
const forGraph = await getSourceCode(cardUri);
|
|
55
|
+
void forGraph.ast;
|
|
56
|
+
// …and the lint reads the same file object.
|
|
57
|
+
await app.get(cardUri).load();
|
|
58
|
+
void app.get(cardUri).ast;
|
|
59
|
+
(0, vitest_1.expect)(forGraph).toBe(app.get(cardUri));
|
|
60
|
+
(0, vitest_1.expect)(liquid.mock.calls.length).toBe(1);
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.it)('falls back for a URI the app does not contain', async () => {
|
|
63
|
+
const app = platformos_common_1.App.fromPaths(ROOT, [], fsOver({}), parsers_1.graphParsers);
|
|
64
|
+
const outside = 'file:///elsewhere/thing.liquid';
|
|
65
|
+
const result = await (0, parsers_1.appBackedGetSourceCode)(app, async (target) => (0, toSourceCode_1.toSourceCode)(target, '<b>outside</b>'))(outside);
|
|
66
|
+
(0, vitest_1.expect)(result.uri).toBe(outside);
|
|
67
|
+
(0, vitest_1.expect)(result.source).toBe('<b>outside</b>');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=parsers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AgC,CAAC;QAEjD,MAAM,MAAM,GAAG,MAAM,IAAA,gCAAsB,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAChE,IAAA,2BAAY,EAAC,MAAM,EAAE,gBAAgB,CAAC,CACvC,CAAC,OAAO,CAAC,CAAC;QAEX,IAAA,eAAM,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/toSourceCode.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { UriString } from '@platformos/platformos-check-common';
|
|
2
|
-
import { Program } from 'acorn';
|
|
3
2
|
import { FileSourceCode } from './types';
|
|
4
|
-
|
|
3
|
+
import { parseJs } from './parsers';
|
|
4
|
+
export { parseJs };
|
|
5
|
+
/**
|
|
6
|
+
* Build a source code for a graph node from contents already in hand.
|
|
7
|
+
*
|
|
8
|
+
* This is the path for callers with no `App`: an in-flight editor buffer, a fixture,
|
|
9
|
+
* a URI from outside the project. Callers that DO have one should pass
|
|
10
|
+
* `appBackedGetSourceCode(app, …)` as `getSourceCode` instead — that is what makes a
|
|
11
|
+
* graph build and a lint run share one parse per file rather than doing one each.
|
|
12
|
+
*
|
|
13
|
+
* The JS and image-asset parses come from {@link graphParsers}, so there is exactly
|
|
14
|
+
* one definition of how each is handled whether the file arrives through the App
|
|
15
|
+
* model or through here.
|
|
16
|
+
*/
|
|
5
17
|
export declare function toSourceCode(uri: UriString, source: string): Promise<FileSourceCode>;
|
package/dist/toSourceCode.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJs =
|
|
3
|
+
exports.parseJs = void 0;
|
|
4
4
|
exports.toSourceCode = toSourceCode;
|
|
5
5
|
const platformos_check_common_1 = require("@platformos/platformos-check-common");
|
|
6
|
-
const
|
|
6
|
+
const platformos_common_1 = require("@platformos/platformos-common");
|
|
7
|
+
const parsers_1 = require("./parsers");
|
|
8
|
+
Object.defineProperty(exports, "parseJs", { enumerable: true, get: function () { return parsers_1.parseJs; } });
|
|
7
9
|
const utils_1 = require("./utils");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Build a source code for a graph node from contents already in hand.
|
|
12
|
+
*
|
|
13
|
+
* This is the path for callers with no `App`: an in-flight editor buffer, a fixture,
|
|
14
|
+
* a URI from outside the project. Callers that DO have one should pass
|
|
15
|
+
* `appBackedGetSourceCode(app, …)` as `getSourceCode` instead — that is what makes a
|
|
16
|
+
* graph build and a lint run share one parse per file rather than doing one each.
|
|
17
|
+
*
|
|
18
|
+
* The JS and image-asset parses come from {@link graphParsers}, so there is exactly
|
|
19
|
+
* one definition of how each is handled whether the file arrives through the App
|
|
20
|
+
* model or through here.
|
|
21
|
+
*/
|
|
19
22
|
async function toSourceCode(uri, source) {
|
|
20
23
|
const extension = (0, utils_1.extname)(uri);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// `sourceCodeTypeOf` is the single answer to which extensions check-common
|
|
25
|
+
// parses; `.json` is the one addition, and only because `tcToSourceCode` models
|
|
26
|
+
// an unrecognised buffer as JSON for the editor (see its doc comment). Anything
|
|
27
|
+
// else is an asset, parsed — or not — by `graphParsers`.
|
|
28
|
+
if ((0, platformos_common_1.sourceCodeTypeOf)(uri) !== undefined || extension === 'json') {
|
|
26
29
|
return (0, platformos_check_common_1.toSourceCode)(uri, source);
|
|
27
30
|
}
|
|
28
|
-
const
|
|
31
|
+
const parse = parsers_1.graphParsers.extensions?.[extension];
|
|
32
|
+
const ast = (parse ? parse(source, uri) : new Error('File parsing not implemented'));
|
|
29
33
|
const assetSourceCode = { type: 'asset', uri, source, ast };
|
|
30
34
|
return assetSourceCode;
|
|
31
35
|
}
|
package/dist/toSourceCode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toSourceCode.js","sourceRoot":"","sources":["../src/toSourceCode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toSourceCode.js","sourceRoot":"","sources":["../src/toSourceCode.ts"],"names":[],"mappings":";;;AAoBA,oCAkBC;AAtCD,iFAAgG;AAChG,qEAAiE;AAEjE,uCAAkD;AAGzC,wFAHc,iBAAO,OAGd;AAFhB,mCAAkC;AAIlC;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,YAAY,CAAC,GAAc,EAAE,MAAc;IAC/D,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;IAE/B,2EAA2E;IAC3E,gFAAgF;IAChF,gFAAgF;IAChF,yDAAyD;IACzD,IAAI,IAAA,oCAAgB,EAAC,GAAG,CAAC,KAAK,SAAS,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;QAChE,OAAO,IAAA,sCAAc,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,KAAK,GAAG,sBAAY,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,CACV,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAC7C,CAAC;IAE5B,MAAM,eAAe,GAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC7E,OAAO,eAAe,CAAC;AACzB,CAAC"}
|