|
1 |
| -import ext_lib from './External libraries.json' |
2 |
| -import source_1 from './source_1.json' |
3 |
| -import source_1_typed from './source_1_typed.json' |
4 |
| -import source_2 from './source_2.json' |
5 |
| -import source_2_typed from './source_2_typed.json' |
6 |
| -import source_3 from './source_3.json' |
7 |
| -import source_3_concurrent from './source_3_concurrent.json' |
8 |
| -import source_3_typed from './source_3_typed.json' |
9 |
| -import source_4 from './source_4.json' |
10 |
| -import source_4_explicit_control from './source_4_explicit-control.json' |
11 |
| -import source_4_typed from './source_4_typed.json' |
| 1 | +import * as ext_lib from './External libraries.json' |
| 2 | +import * as source_1 from './source_1.json' |
| 3 | +import * as source_1_typed from './source_1_typed.json' |
| 4 | +import * as source_2 from './source_2.json' |
| 5 | +import * as source_2_typed from './source_2_typed.json' |
| 6 | +import * as source_3 from './source_3.json' |
| 7 | +import * as source_3_concurrent from './source_3_concurrent.json' |
| 8 | +import * as source_3_typed from './source_3_typed.json' |
| 9 | +import * as source_4 from './source_4.json' |
| 10 | +import * as source_4_typed from './source_4_typed.json' |
| 11 | +import * as source_4_explicit_control from './source_4_explicit-control.json' |
| 12 | + |
| 13 | +// (18 March 2022) |
| 14 | +// Problem to be fixed in the future: |
| 15 | +// |
| 16 | +// There seems to be an inconsistency between how jest and how typescript |
| 17 | +// behaves when encountering imports of the form `import * as x from 'x.json'` |
| 18 | +// jest will set x = jsonobject, |
| 19 | +// but typescript will instead set x = { default: jsonobject } |
| 20 | +// |
| 21 | +// This means that under typescript, we want `import x from 'x.json'`, |
| 22 | +// while under jest, we want `import * as x from 'x.json'` |
| 23 | +// |
| 24 | +// This problem was hidden when transpiling to CommonJS modules before, which |
| 25 | +// behaves similarly to jest. But now that we are transpiling to es6, |
| 26 | +// typescript projects that depend on js-slang may now be exposed to this |
| 27 | +// inconsistency. |
| 28 | +// |
| 29 | +// For now, we use brute force until the landscape changes or someone thinks of |
| 30 | +// a proper solution. |
| 31 | +function resolveImportInconsistency(json: any) { |
| 32 | + // `json` doesn't inherit from `Object`? |
| 33 | + // Can't use hasOwnProperty for some reason. |
| 34 | + if ('default' in json) { |
| 35 | + return json.default |
| 36 | + } else { |
| 37 | + return json |
| 38 | + } |
| 39 | +} |
12 | 40 |
|
13 | 41 | export const SourceDocumentation = {
|
14 | 42 | builtins: {
|
15 |
| - '1': source_1, |
16 |
| - '1_typed': source_1_typed, |
17 |
| - '2': source_2, |
18 |
| - '2_typed': source_2_typed, |
19 |
| - '3': source_3, |
20 |
| - '3_concurrent': source_3_concurrent, |
21 |
| - '3_typed': source_3_typed, |
22 |
| - '4': source_4, |
23 |
| - '4_typed': source_4_typed, |
24 |
| - '4_explicit-control': source_4_explicit_control |
| 43 | + '1': resolveImportInconsistency(source_1), |
| 44 | + '1_typed': resolveImportInconsistency(source_1_typed), |
| 45 | + '2': resolveImportInconsistency(source_2), |
| 46 | + '2_typed': resolveImportInconsistency(source_2_typed), |
| 47 | + '3': resolveImportInconsistency(source_3), |
| 48 | + '3_concurrent': resolveImportInconsistency(source_3_concurrent), |
| 49 | + '3_typed': resolveImportInconsistency(source_3_typed), |
| 50 | + '4': resolveImportInconsistency(source_4), |
| 51 | + '4_typed': resolveImportInconsistency(source_4_typed), |
| 52 | + '4_explicit-control': resolveImportInconsistency(source_4_explicit_control) |
25 | 53 | },
|
26 | 54 | ext_lib
|
27 |
| -} as const |
| 55 | +} |
0 commit comments