Skip to content

Commit 225e4c1

Browse files
committed
fix: impossible to set "js-ir" as target platform
1 parent b729a75 commit 225e4c1

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

src/executable-code/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class ExecutableCode {
8686
const args = targetNode.hasAttribute(ATTRIBUTES.ARGUMENTS) ? targetNode.getAttribute(ATTRIBUTES.ARGUMENTS) : "";
8787
const hiddenDependencies = this.getHiddenDependencies(targetNode);
8888
const outputHeight = targetNode.getAttribute(ATTRIBUTES.OUTPUT_HEIGHT) || null;
89-
const targetPlatform = getTargetById(targetNode.getAttribute(ATTRIBUTES.PLATFORM));
89+
const targetPlatform = getTargetById(targetNode.getAttribute(ATTRIBUTES.PLATFORM)) || TargetPlatforms.JAVA;
9090
const targetNodeStyle = targetNode.getAttribute(ATTRIBUTES.STYLE);
9191
const jsLibs = this.getJsLibraries(targetNode, targetPlatform);
9292
const isFoldedButton = targetNode.getAttribute(ATTRIBUTES.FOLDED_BUTTON) !== "false";

src/lib/crosslink.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { compressToBase64 } from 'lz-string';
22

3-
import { isKeyOfObject } from '../utils/types';
4-
import { TargetPlatforms, TargetPlatformsKeys } from '../utils/platforms';
3+
import { getTargetById, TargetPlatformsKeys } from '../utils/platforms';
54

65
import {
76
escapeRegExp,
@@ -34,11 +33,8 @@ export function generateCrosslink(code: string, options?: LinkOptions) {
3433

3534
if (options && options.targetPlatform) {
3635
const target =
37-
options.targetPlatform && options.targetPlatform.toUpperCase();
38-
39-
if (!isKeyOfObject(target, TargetPlatforms))
40-
throw new Error('Invalid target platform');
41-
36+
options.targetPlatform && getTargetById(options.targetPlatform);
37+
if (!target) throw new Error('Invalid target platform');
4238
opts.targetPlatform = options.targetPlatform;
4339
}
4440

src/utils/platforms/TargetPlatform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default class TargetPlatform {
2-
private id: string;
3-
private printableName: string;
2+
id: string;
3+
printableName: string;
44

55
constructor(id: string, printableName: string) {
66
this.id = id;

src/utils/platforms/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { isKeyOfObject } from '../types';
2-
31
import TargetPlatform from './TargetPlatform';
42
import { TargetPlatforms } from './TargetPlatforms';
3+
import { isKeyOfObject } from '../types';
54

65
export function getTargetById(id?: string | null) {
7-
const key = id && id.toUpperCase();
8-
return key && isKeyOfObject(key, TargetPlatforms)
9-
? TargetPlatforms[key]
10-
: TargetPlatforms.JAVA;
6+
const key = id && id.toUpperCase().replace(/-/g, '_');
7+
8+
return isKeyOfObject(key, TargetPlatforms) ? TargetPlatforms[key] : null;
119
}
1210

1311
export function isJavaRelated(platform: TargetPlatform) {

0 commit comments

Comments
 (0)