@cedarjs/structure 2.8.1-next.116 → 2.8.1-rc.3

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 (110) hide show
  1. package/README.md +1 -1
  2. package/dist/errors.js +15 -9
  3. package/dist/index.d.ts +7 -7
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +67 -40
  6. package/dist/model/RWCell.d.ts +4 -4
  7. package/dist/model/RWCell.d.ts.map +1 -1
  8. package/dist/model/RWCell.js +103 -111
  9. package/dist/model/RWComponent.d.ts +2 -2
  10. package/dist/model/RWComponent.d.ts.map +1 -1
  11. package/dist/model/RWComponent.js +41 -46
  12. package/dist/model/RWEnvHelper.d.ts +4 -4
  13. package/dist/model/RWEnvHelper.d.ts.map +1 -1
  14. package/dist/model/RWEnvHelper.js +205 -212
  15. package/dist/model/RWFunction.d.ts +2 -2
  16. package/dist/model/RWFunction.d.ts.map +1 -1
  17. package/dist/model/RWFunction.js +15 -10
  18. package/dist/model/RWLayout.d.ts +2 -2
  19. package/dist/model/RWLayout.d.ts.map +1 -1
  20. package/dist/model/RWLayout.js +15 -10
  21. package/dist/model/RWPage.d.ts +3 -3
  22. package/dist/model/RWPage.d.ts.map +1 -1
  23. package/dist/model/RWPage.js +57 -61
  24. package/dist/model/RWProject.d.ts +17 -11
  25. package/dist/model/RWProject.d.ts.map +1 -1
  26. package/dist/model/RWProject.js +164 -218
  27. package/dist/model/RWRoute.d.ts +5 -5
  28. package/dist/model/RWRoute.d.ts.map +1 -1
  29. package/dist/model/RWRoute.js +262 -312
  30. package/dist/model/RWRouter.d.ts +4 -4
  31. package/dist/model/RWRouter.d.ts.map +1 -1
  32. package/dist/model/RWRouter.js +126 -130
  33. package/dist/model/RWSDL.d.ts +5 -5
  34. package/dist/model/RWSDL.d.ts.map +1 -1
  35. package/dist/model/RWSDL.js +84 -96
  36. package/dist/model/RWSDLField.d.ts +6 -6
  37. package/dist/model/RWSDLField.d.ts.map +1 -1
  38. package/dist/model/RWSDLField.js +81 -79
  39. package/dist/model/RWService.d.ts +4 -4
  40. package/dist/model/RWService.d.ts.map +1 -1
  41. package/dist/model/RWService.js +76 -76
  42. package/dist/model/RWServiceFunction.d.ts +4 -4
  43. package/dist/model/RWServiceFunction.d.ts.map +1 -1
  44. package/dist/model/RWServiceFunction.js +97 -95
  45. package/dist/model/RWTOML.d.ts +3 -3
  46. package/dist/model/RWTOML.d.ts.map +1 -1
  47. package/dist/model/RWTOML.js +55 -53
  48. package/dist/model/index.d.ts +2 -2
  49. package/dist/model/index.d.ts.map +1 -1
  50. package/dist/model/index.js +20 -3
  51. package/dist/model/util/process_env.js +62 -44
  52. package/dist/nodes.d.ts +2 -2
  53. package/dist/nodes.d.ts.map +1 -1
  54. package/dist/nodes.js +164 -171
  55. package/dist/util.js +33 -23
  56. package/dist/x/Array.js +25 -15
  57. package/dist/x/Location.d.ts +1 -1
  58. package/dist/x/Location.d.ts.map +1 -1
  59. package/dist/x/Location.js +17 -11
  60. package/dist/x/Position.js +29 -18
  61. package/dist/x/Range.d.ts +1 -1
  62. package/dist/x/Range.d.ts.map +1 -1
  63. package/dist/x/Range.js +22 -17
  64. package/dist/x/URL.js +75 -59
  65. package/dist/x/child_process.d.ts +1 -1
  66. package/dist/x/child_process.d.ts.map +1 -1
  67. package/dist/x/child_process.js +49 -35
  68. package/dist/x/decorators.d.ts +2 -2
  69. package/dist/x/decorators.d.ts.map +1 -1
  70. package/dist/x/decorators.js +26 -46
  71. package/dist/x/diagnostics.d.ts +3 -3
  72. package/dist/x/diagnostics.d.ts.map +1 -1
  73. package/dist/x/diagnostics.js +259 -163
  74. package/dist/x/path.js +55 -36
  75. package/dist/x/prisma.d.ts +2 -2
  76. package/dist/x/prisma.d.ts.map +1 -1
  77. package/dist/x/prisma.js +55 -32
  78. package/dist/x/ts-morph.js +45 -34
  79. package/package.json +17 -38
  80. package/dist/errors.js.map +0 -1
  81. package/dist/index.js.map +0 -1
  82. package/dist/model/RWCell.js.map +0 -1
  83. package/dist/model/RWComponent.js.map +0 -1
  84. package/dist/model/RWEnvHelper.js.map +0 -1
  85. package/dist/model/RWFunction.js.map +0 -1
  86. package/dist/model/RWLayout.js.map +0 -1
  87. package/dist/model/RWPage.js.map +0 -1
  88. package/dist/model/RWProject.js.map +0 -1
  89. package/dist/model/RWRoute.js.map +0 -1
  90. package/dist/model/RWRouter.js.map +0 -1
  91. package/dist/model/RWSDL.js.map +0 -1
  92. package/dist/model/RWSDLField.js.map +0 -1
  93. package/dist/model/RWService.js.map +0 -1
  94. package/dist/model/RWServiceFunction.js.map +0 -1
  95. package/dist/model/RWTOML.js.map +0 -1
  96. package/dist/model/index.js.map +0 -1
  97. package/dist/model/util/process_env.js.map +0 -1
  98. package/dist/nodes.js.map +0 -1
  99. package/dist/util.js.map +0 -1
  100. package/dist/x/Array.js.map +0 -1
  101. package/dist/x/Location.js.map +0 -1
  102. package/dist/x/Position.js.map +0 -1
  103. package/dist/x/Range.js.map +0 -1
  104. package/dist/x/URL.js.map +0 -1
  105. package/dist/x/child_process.js.map +0 -1
  106. package/dist/x/decorators.js.map +0 -1
  107. package/dist/x/diagnostics.js.map +0 -1
  108. package/dist/x/path.js.map +0 -1
  109. package/dist/x/prisma.js.map +0 -1
  110. package/dist/x/ts-morph.js.map +0 -1
@@ -1,54 +1,56 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import * as toml from 'smol-toml';
8
- import { FileNode } from '../nodes.js';
9
- import { lazy } from '../x/decorators.js';
10
- import { err } from '../x/diagnostics.js';
11
- import { Range_create } from '../x/Range.js';
12
- export class RWTOML extends FileNode {
13
- filePath;
14
- parent;
15
- constructor(filePath, parent) {
16
- super();
17
- this.filePath = filePath;
18
- this.parent = parent;
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
6
+ _Object$defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.RWTOML = void 0;
10
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
11
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
12
+ var toml = _interopRequireWildcard(require("smol-toml"));
13
+ var _nodes = require("../nodes");
14
+ var _decorators = require("../x/decorators");
15
+ var _diagnostics = require("../x/diagnostics");
16
+ var _Range = require("../x/Range");
17
+ var _dec, _dec2, _class;
18
+ let RWTOML = exports.RWTOML = (_dec = (0, _decorators.lazy)(), _dec2 = (0, _decorators.lazy)(), _class = class RWTOML extends _nodes.FileNode {
19
+ constructor(filePath, parent) {
20
+ super();
21
+ this.filePath = filePath;
22
+ this.parent = parent;
23
+ }
24
+ // @lazy() get content(): TOML.JsonMap {
25
+ // return TOML.parse(this.text)
26
+ // }
27
+ // TODO: diagnostics
28
+ get parsedTOML() {
29
+ return toml.parse(this.text);
30
+ }
31
+ get web_includeEnvironmentVariables() {
32
+ return this.parsedTOML?.web?.['includeEnvironmentVariables'] ?? [];
33
+ }
34
+ *diagnostics() {
35
+ try {
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
37
+ this.parsedTOML;
38
+ } catch (e) {
39
+ const pos = {
40
+ line: e.line - 1,
41
+ character: e.column - 1
42
+ };
43
+ const range = (0, _Range.Range_create)(pos, pos);
44
+ // Forward the TOML parse error with correct location information
45
+ yield (0, _diagnostics.err)({
46
+ uri: this.uri,
47
+ range
48
+ }, 'TOML Parser Error: ' + e.message);
49
+ return;
19
50
  }
20
- // @lazy() get content(): TOML.JsonMap {
21
- // return TOML.parse(this.text)
22
- // }
23
- // TODO: diagnostics
24
- get parsedTOML() {
25
- return toml.parse(this.text);
26
- }
27
- get web_includeEnvironmentVariables() {
28
- return this.parsedTOML?.web?.['includeEnvironmentVariables'] ?? [];
29
- }
30
- *diagnostics() {
31
- try {
32
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
33
- this.parsedTOML;
34
- }
35
- catch (e) {
36
- const pos = { line: e.line - 1, character: e.column - 1 };
37
- const range = Range_create(pos, pos);
38
- // Forward the TOML parse error with correct location information
39
- yield err({ uri: this.uri, range }, 'TOML Parser Error: ' + e.message);
40
- return;
41
- }
42
- // at this point we know that the TOML was parsed successfully
43
- //this.parsedTOML //?
44
- //const allowedTopElements = ['web', 'api']
45
- // TODO: check that schema is correct
46
- }
47
- }
48
- __decorate([
49
- lazy()
50
- ], RWTOML.prototype, "parsedTOML", null);
51
- __decorate([
52
- lazy()
53
- ], RWTOML.prototype, "web_includeEnvironmentVariables", null);
54
- //# sourceMappingURL=RWTOML.js.map
51
+ // at this point we know that the TOML was parsed successfully
52
+ //this.parsedTOML //?
53
+ //const allowedTopElements = ['web', 'api']
54
+ // TODO: check that schema is correct
55
+ }
56
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "parsedTOML", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "parsedTOML"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "web_includeEnvironmentVariables", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "web_includeEnvironmentVariables"), _class.prototype), _class);
@@ -1,3 +1,3 @@
1
- export { RWProject } from './RWProject.js';
2
- export { RWRoute } from './RWRoute.js';
1
+ export { RWProject } from './RWProject';
2
+ export { RWRoute } from './RWRoute';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA"}
@@ -1,3 +1,20 @@
1
- export { RWProject } from './RWProject.js';
2
- export { RWRoute } from './RWRoute.js';
3
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ _Object$defineProperty(exports, "RWProject", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _RWProject.RWProject;
11
+ }
12
+ });
13
+ _Object$defineProperty(exports, "RWRoute", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _RWRoute.RWRoute;
17
+ }
18
+ });
19
+ var _RWProject = require("./RWProject");
20
+ var _RWRoute = require("./RWRoute");
@@ -1,49 +1,67 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import * as tsm from 'ts-morph';
4
- import { globSync } from '../../x/path.js';
5
- import { createTSMSourceFile_cached } from '../../x/ts-morph.js';
6
- export function process_env_findAll(dir) {
7
- const globPath = path.join(dir, 'src/**/*.{js,ts,jsx,tsx}');
8
- return globSync(globPath).flatMap((file) => process_env_findInFile(file, fs.readFileSync(file).toString()));
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
6
+ _Object$defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.process_env_findAll = process_env_findAll;
10
+ exports.process_env_findInFile = process_env_findInFile;
11
+ exports.process_env_findInFile2 = process_env_findInFile2;
12
+ require("core-js/modules/es.array.push.js");
13
+ var _flatMap = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/flat-map"));
14
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/includes"));
15
+ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/filter"));
16
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
17
+ var _nodePath = _interopRequireDefault(require("node:path"));
18
+ var tsm = _interopRequireWildcard(require("ts-morph"));
19
+ var _path = require("../../x/path");
20
+ var _tsMorph2 = require("../../x/ts-morph");
21
+ function process_env_findAll(dir) {
22
+ var _context;
23
+ const globPath = _nodePath.default.join(dir, 'src/**/*.{js,ts,jsx,tsx}');
24
+ return (0, _flatMap.default)(_context = (0, _path.globSync)(globPath)).call(_context, file => process_env_findInFile(file, _nodeFs.default.readFileSync(file).toString()));
9
25
  }
10
- export function process_env_findInFile(filePath, text) {
11
- if (!text.includes('process.env')) {
12
- return [];
13
- }
14
- try {
15
- return process_env_findInFile2(createTSMSourceFile_cached(filePath, text));
16
- }
17
- catch {
18
- return [];
19
- }
26
+ function process_env_findInFile(filePath, text) {
27
+ if (!(0, _includes.default)(text).call(text, 'process.env')) {
28
+ return [];
29
+ }
30
+ try {
31
+ return process_env_findInFile2((0, _tsMorph2.createTSMSourceFile_cached)(filePath, text));
32
+ } catch {
33
+ return [];
34
+ }
20
35
  }
21
- export function process_env_findInFile2(sf) {
22
- const penvs = sf
23
- .getDescendantsOfKind(tsm.SyntaxKind.PropertyAccessExpression)
24
- .filter(is_process_env);
25
- const results = [];
26
- for (const penv of penvs) {
27
- const node = penv.getParent();
28
- if (!node) {
29
- continue;
30
- }
31
- if (tsm.Node.isPropertyAccessExpression(node)) {
32
- results.push({ key: node.getName(), node });
33
- }
34
- else if (tsm.Node.isElementAccessExpression(node)) {
35
- const arg = node.getArgumentExpression();
36
- if (arg && tsm.Node.isStringLiteral(arg)) {
37
- results.push({ key: arg.getLiteralText(), node });
38
- }
39
- }
36
+ function process_env_findInFile2(sf) {
37
+ var _context2;
38
+ const penvs = (0, _filter.default)(_context2 = sf.getDescendantsOfKind(tsm.SyntaxKind.PropertyAccessExpression)).call(_context2, is_process_env);
39
+ const results = [];
40
+ for (const penv of penvs) {
41
+ const node = penv.getParent();
42
+ if (!node) {
43
+ continue;
40
44
  }
41
- return results;
42
- }
43
- function is_process_env(n) {
44
- if (!tsm.Node.isPropertyAccessExpression(n)) {
45
- return false;
45
+ if (tsm.Node.isPropertyAccessExpression(node)) {
46
+ results.push({
47
+ key: node.getName(),
48
+ node
49
+ });
50
+ } else if (tsm.Node.isElementAccessExpression(node)) {
51
+ const arg = node.getArgumentExpression();
52
+ if (arg && tsm.Node.isStringLiteral(arg)) {
53
+ results.push({
54
+ key: arg.getLiteralText(),
55
+ node
56
+ });
57
+ }
46
58
  }
47
- return n.getExpression().getText() === 'process' && n.getName() === 'env';
59
+ }
60
+ return results;
48
61
  }
49
- //# sourceMappingURL=process_env.js.map
62
+ function is_process_env(n) {
63
+ if (!tsm.Node.isPropertyAccessExpression(n)) {
64
+ return false;
65
+ }
66
+ return n.getExpression().getText() === 'process' && n.getName() === 'env';
67
+ }
package/dist/nodes.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type * as tsm from 'ts-morph';
2
- import type { ArrayLike } from './x/Array.js';
3
- import type { ExtendedDiagnostic } from './x/diagnostics.js';
2
+ import type { ArrayLike } from './x/Array';
3
+ import type { ExtendedDiagnostic } from './x/diagnostics';
4
4
  export type NodeID = string;
5
5
  export declare abstract class BaseNode {
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src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+1,175 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { existsSync, readFileSync } from 'node:fs';
8
- import { basename } from 'node:path';
9
- import { ArrayLike_normalize } from './x/Array.js';
10
- import { lazy, memo } from './x/decorators.js';
11
- import { basenameNoExt } from './x/path.js';
12
- import { Range_create } from './x/Range.js';
13
- import { createTSMSourceFile_cached } from './x/ts-morph.js';
14
- import { URL_file } from './x/URL.js';
15
- export class BaseNode {
16
- exists = true;
17
- /**
18
- * Returns the children of this node.
19
- * Override this.
20
- */
21
- children() {
22
- return [];
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.FileNode = exports.BaseNode = void 0;
9
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/json/stringify"));
10
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/promise"));
11
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/map"));
12
+ var _flat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/flat"));
13
+ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/filter"));
14
+ var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/starts-with"));
15
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
16
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
17
+ var _nodeFs = require("node:fs");
18
+ var _nodePath = require("node:path");
19
+ var _Array = require("./x/Array");
20
+ var _decorators = require("./x/decorators");
21
+ var _path = require("./x/path");
22
+ var _Range = require("./x/Range");
23
+ var _tsMorph = require("./x/ts-morph");
24
+ var _URL = require("./x/URL");
25
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _dec6, _dec7, _dec8, _dec9, _dec0, _dec1, _dec10, _class2;
26
+ let BaseNode = exports.BaseNode = (_dec = (0, _decorators.memo)(), _dec2 = (0, _decorators.memo)(), _dec3 = (0, _decorators.memo)(_stringify.default), _dec4 = (0, _decorators.lazy)(), _dec5 = (0, _decorators.memo)(), _class = class BaseNode {
27
+ constructor() {
28
+ this.exists = true;
29
+ }
30
+ /**
31
+ * Each node MUST have a unique ID.
32
+ * IDs have meaningful information.
33
+ *
34
+ * examples:
35
+ * - /path/to/project
36
+ * - /path/to/project/web/src/Routes.js
37
+ * - /path/to/project/web/src/Routes.js /route1
38
+ */
39
+ /**
40
+ * Returns the children of this node.
41
+ * Override this.
42
+ */
43
+ children() {
44
+ return [];
45
+ }
46
+ _children() {
47
+ return (0, _Array.ArrayLike_normalize)(this.children());
48
+ }
49
+
50
+ /**
51
+ * Diagnostics for this node (must not include children's diagnostics).
52
+ * Override this.
53
+ */
54
+ diagnostics() {
55
+ return [];
56
+ }
57
+ _diagnostics() {
58
+ return (0, _Array.ArrayLike_normalize)(this.diagnostics());
59
+ }
60
+
61
+ /**
62
+ * Collects diagnostics for this node and all descendants.
63
+ * This is what you'll use to gather all the project diagnostics.
64
+ */
65
+ async collectDiagnostics(uri) {
66
+ // TODO: catch runtime errors and add them as diagnostics
67
+ // TODO: we can parallelize this further
68
+ if (uri && this.bailOutOnCollection(uri)) {
69
+ return [];
23
70
  }
24
- _children() {
25
- return ArrayLike_normalize(this.children());
26
- }
27
- /**
28
- * Diagnostics for this node (must not include children's diagnostics).
29
- * Override this.
30
- */
31
- diagnostics() {
32
- return [];
33
- }
34
- _diagnostics() {
35
- return ArrayLike_normalize(this.diagnostics());
36
- }
37
- /**
38
- * Collects diagnostics for this node and all descendants.
39
- * This is what you'll use to gather all the project diagnostics.
40
- */
41
- async collectDiagnostics(uri) {
42
- // TODO: catch runtime errors and add them as diagnostics
43
- // TODO: we can parallelize this further
44
- if (uri && this.bailOutOnCollection(uri)) {
45
- return [];
46
- }
47
- try {
48
- const d1 = await this._diagnostics();
49
- const dd = await Promise.all((await this._children()).map((c) => c.collectDiagnostics(uri)));
50
- const d2 = dd.flat();
51
- let all = [...d1, ...d2];
52
- if (uri) {
53
- all = all.filter((x) => x.uri === uri);
54
- }
55
- return all;
56
- }
57
- catch (e) {
58
- const uri = this.closestContainingUri;
59
- if (!uri) {
60
- throw e;
61
- }
62
- const range = Range_create(0, 0, 0, 0);
63
- return [
64
- {
65
- uri,
66
- diagnostic: { message: e + '', range },
67
- },
68
- ];
69
- }
70
- }
71
- bailOutOnCollection(uri) {
72
- if (this.id === uri) {
73
- return false;
71
+ try {
72
+ var _context;
73
+ const d1 = await this._diagnostics();
74
+ const dd = await _promise.default.all((0, _map.default)(_context = await this._children()).call(_context, c => c.collectDiagnostics(uri)));
75
+ const d2 = (0, _flat.default)(dd).call(dd);
76
+ let all = [...d1, ...d2];
77
+ if (uri) {
78
+ all = (0, _filter.default)(all).call(all, x => x.uri === uri);
79
+ }
80
+ return all;
81
+ } catch (e) {
82
+ const uri = this.closestContainingUri;
83
+ if (!uri) {
84
+ throw e;
85
+ }
86
+ const range = (0, _Range.Range_create)(0, 0, 0, 0);
87
+ return [{
88
+ uri,
89
+ diagnostic: {
90
+ message: e + '',
91
+ range
74
92
  }
75
- if (uri.startsWith(this.id)) {
76
- return false;
77
- }
78
- return true;
93
+ }];
79
94
  }
80
- get closestContainingUri() {
81
- const { uri } = this;
82
- if (uri) {
83
- return uri;
84
- }
85
- if (this.parent) {
86
- return this.parent.closestContainingUri;
87
- }
88
- return undefined;
95
+ }
96
+ bailOutOnCollection(uri) {
97
+ if (this.id === uri) {
98
+ return false;
89
99
  }
90
- /**
91
- * Finds a node by ID.
92
- * The default algorithm tries to be economic and only create the necessary
93
- * intermediate nodes.
94
- * Subclasses can override this to add further optimizations.
95
- * @param id
96
- */
97
- async findNode(id) {
98
- id = URL_file(id);
99
- if (this.id === id) {
100
- return this;
101
- }
102
- if (id.startsWith(this.id)) {
103
- for (const c of await this._children()) {
104
- // depth first search by default
105
- const cc = await c.findNode(id);
106
- if (cc) {
107
- return cc;
108
- }
109
- }
110
- }
111
- return undefined;
112
- }
113
- }
114
- __decorate([
115
- memo()
116
- ], BaseNode.prototype, "_children", null);
117
- __decorate([
118
- memo()
119
- ], BaseNode.prototype, "_diagnostics", null);
120
- __decorate([
121
- memo((...args) => JSON.stringify(args))
122
- ], BaseNode.prototype, "collectDiagnostics", null);
123
- __decorate([
124
- lazy()
125
- ], BaseNode.prototype, "closestContainingUri", null);
126
- __decorate([
127
- memo()
128
- ], BaseNode.prototype, "findNode", null);
129
- export class FileNode extends BaseNode {
130
- get uri() {
131
- return URL_file(this.filePath);
100
+ if ((0, _startsWith.default)(uri).call(uri, this.id)) {
101
+ return false;
132
102
  }
133
- /**
134
- * the ID of a FileNode is its file:// uri.
135
- */
136
- get id() {
137
- return this.uri;
103
+ return true;
104
+ }
105
+ get closestContainingUri() {
106
+ const {
107
+ uri
108
+ } = this;
109
+ if (uri) {
110
+ return uri;
138
111
  }
139
- get text() {
140
- return readFileSync(this.filePath, { encoding: 'utf8' }).toString();
112
+ if (this.parent) {
113
+ return this.parent.closestContainingUri;
141
114
  }
142
- get fileExists() {
143
- return existsSync(this.filePath);
115
+ return undefined;
116
+ }
117
+
118
+ /**
119
+ * Finds a node by ID.
120
+ * The default algorithm tries to be economic and only create the necessary
121
+ * intermediate nodes.
122
+ * Subclasses can override this to add further optimizations.
123
+ * @param id
124
+ */
125
+ async findNode(id) {
126
+ id = (0, _URL.URL_file)(id);
127
+ if (this.id === id) {
128
+ return this;
144
129
  }
145
- /**
146
- * parsed ts-morph source file
147
- */
148
- get sf() {
149
- if (typeof this.text === 'undefined') {
150
- throw new Error('undefined file ' + this.filePath);
130
+ if ((0, _startsWith.default)(id).call(id, this.id)) {
131
+ for (const c of await this._children()) {
132
+ // depth first search by default
133
+ const cc = await c.findNode(id);
134
+ if (cc) {
135
+ return cc;
151
136
  }
152
- return createTSMSourceFile_cached(this.filePath, this.text);
153
- }
154
- get basenameNoExt() {
155
- return basenameNoExt(this.filePath);
137
+ }
156
138
  }
157
- get basename() {
158
- return basename(this.filePath);
139
+ return undefined;
140
+ }
141
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_children", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "_children"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_diagnostics", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "_diagnostics"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "collectDiagnostics", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "collectDiagnostics"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "closestContainingUri", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "closestContainingUri"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "findNode", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "findNode"), _class.prototype), _class);
142
+ let FileNode = exports.FileNode = (_dec6 = (0, _decorators.lazy)(), _dec7 = (0, _decorators.lazy)(), _dec8 = (0, _decorators.lazy)(), _dec9 = (0, _decorators.lazy)(), _dec0 = (0, _decorators.lazy)(), _dec1 = (0, _decorators.lazy)(), _dec10 = (0, _decorators.lazy)(), _class2 = class FileNode extends BaseNode {
143
+ get uri() {
144
+ return (0, _URL.URL_file)(this.filePath);
145
+ }
146
+ /**
147
+ * the ID of a FileNode is its file:// uri.
148
+ */
149
+ get id() {
150
+ return this.uri;
151
+ }
152
+ get text() {
153
+ return (0, _nodeFs.readFileSync)(this.filePath, {
154
+ encoding: 'utf8'
155
+ }).toString();
156
+ }
157
+ get fileExists() {
158
+ return (0, _nodeFs.existsSync)(this.filePath);
159
+ }
160
+ /**
161
+ * parsed ts-morph source file
162
+ */
163
+ get sf() {
164
+ if (typeof this.text === 'undefined') {
165
+ throw new Error('undefined file ' + this.filePath);
159
166
  }
160
- }
161
- __decorate([
162
- lazy()
163
- ], FileNode.prototype, "uri", null);
164
- __decorate([
165
- lazy()
166
- ], FileNode.prototype, "id", null);
167
- __decorate([
168
- lazy()
169
- ], FileNode.prototype, "text", null);
170
- __decorate([
171
- lazy()
172
- ], FileNode.prototype, "fileExists", null);
173
- __decorate([
174
- lazy()
175
- ], FileNode.prototype, "sf", null);
176
- __decorate([
177
- lazy()
178
- ], FileNode.prototype, "basenameNoExt", null);
179
- __decorate([
180
- lazy()
181
- ], FileNode.prototype, "basename", null);
182
- //# sourceMappingURL=nodes.js.map
167
+ return (0, _tsMorph.createTSMSourceFile_cached)(this.filePath, this.text);
168
+ }
169
+ get basenameNoExt() {
170
+ return (0, _path.basenameNoExt)(this.filePath);
171
+ }
172
+ get basename() {
173
+ return (0, _nodePath.basename)(this.filePath);
174
+ }
175
+ }, (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "uri", [_dec6], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "uri"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "id", [_dec7], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "id"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "text", [_dec8], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "text"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "fileExists", [_dec9], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "fileExists"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "sf", [_dec0], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "sf"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "basenameNoExt", [_dec1], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "basenameNoExt"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "basename", [_dec10], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "basename"), _class2.prototype), _class2);