@bablr/bablr-vm 0.22.0 → 0.23.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/lib/context.js CHANGED
@@ -1,13 +1,5 @@
1
1
  import { buildDependentLanguages } from '@bablr/helpers/grammar';
2
2
  import { facades, actuals } from './facades.js';
3
- import { getPrototypeOf } from '@bablr/helpers/object';
4
- import { states as nodeStates } from './node.js';
5
- import { PathFacade as Path } from '@bablr/agast-vm';
6
-
7
- import { sourceTextFor } from '@bablr/agast-helpers/stream';
8
- import { streamFromTree } from '@bablr/agast-helpers/tree';
9
- import { allTagsFor } from '@bablr/agast-helpers/path-facade';
10
- import { buildEmbeddedNode } from '@bablr/agast-vm-helpers/builders';
11
3
 
12
4
  export const ContextFacade = class BABLRContextFacade {
13
5
  constructor(actual) {
@@ -26,38 +18,6 @@ export const ContextFacade = class BABLRContextFacade {
26
18
  get productionEnhancer() {
27
19
  return actuals.get(this).productionEnhancer;
28
20
  }
29
-
30
- // getCooked(nodeOrRange) {
31
- // return isArray(nodeOrRange)
32
- // ? getCookedFromStream(this.allTagsFor(nodeOrRange))
33
- // : getCookedFromTree(nodeOrRange);
34
- // }
35
-
36
- sourceTextFor(node) {
37
- let fragmentStream;
38
- if (!node) return null;
39
- if (getPrototypeOf(node) === Object.prototype) {
40
- fragmentStream = streamFromTree(node);
41
- } else if (nodeStates.has(node)) {
42
- let state = nodeStates.get(node);
43
- let { tagsIndexRange } = state;
44
- let path = Path.from(state.fragmentNode);
45
-
46
- if (!tagsIndexRange) {
47
- let nodePath = Path.from(state.node);
48
- tagsIndexRange = [0, nodePath.tagPathAt(-1).tagsIndex];
49
- }
50
-
51
- fragmentStream = allTagsFor(
52
- [path.tagPathAt(tagsIndexRange[0], 0), path.tagPathAt(tagsIndexRange[1], -1)],
53
- { unshift: true },
54
- );
55
- } else {
56
- return null;
57
- }
58
-
59
- return fragmentStream && sourceTextFor(fragmentStream);
60
- }
61
21
  };
62
22
 
63
23
  export const Context = class BABLRContext {
@@ -75,10 +35,8 @@ export const Context = class BABLRContext {
75
35
  this.facade = new ContextFacade(this);
76
36
 
77
37
  for (const { 1: language } of this.languages) {
78
- let { prototype } = language.grammar;
79
- while (prototype && prototype !== Object.prototype) {
80
- prototype = getPrototypeOf(prototype);
81
- }
38
+ if (!language) throw new Error();
39
+ if (language.default) throw new Error('Do not use import * as on languages');
82
40
  this.grammars.set(language, new language.grammar());
83
41
  }
84
42
  }