Skip to content

Commit

Permalink
fix: impossible to set "js-ir" as target platform
Browse files Browse the repository at this point in the history
  • Loading branch information
zoobestik committed Dec 19, 2023
1 parent 5a30f25 commit bb31ed5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/executable-code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class ExecutableCode {
const args = targetNode.hasAttribute(ATTRIBUTES.ARGUMENTS) ? targetNode.getAttribute(ATTRIBUTES.ARGUMENTS) : "";
const hiddenDependencies = this.getHiddenDependencies(targetNode);
const outputHeight = targetNode.getAttribute(ATTRIBUTES.OUTPUT_HEIGHT) || null;
const targetPlatform = getTargetById(targetNode.getAttribute(ATTRIBUTES.PLATFORM));
const targetPlatform = getTargetById(targetNode.getAttribute(ATTRIBUTES.PLATFORM)) || TargetPlatforms.JAVA;
const targetNodeStyle = targetNode.getAttribute(ATTRIBUTES.STYLE);
const jsLibs = this.getJsLibraries(targetNode, targetPlatform);
const isFoldedButton = targetNode.getAttribute(ATTRIBUTES.FOLDED_BUTTON) !== "false";
Expand Down
10 changes: 3 additions & 7 deletions src/lib/crosslink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { compressToBase64 } from 'lz-string';

import { isKeyOfObject } from '../utils/types';
import { TargetPlatforms, TargetPlatformsKeys } from '../utils/platforms';
import { getTargetById, TargetPlatformsKeys } from '../utils/platforms';

import {
escapeRegExp,
Expand Down Expand Up @@ -34,11 +33,8 @@ export function generateCrosslink(code: string, options?: LinkOptions) {

if (options && options.targetPlatform) {
const target =
options.targetPlatform && options.targetPlatform.toUpperCase();

if (!isKeyOfObject(target, TargetPlatforms))
throw new Error('Invalid target platform');

options.targetPlatform && getTargetById(options.targetPlatform);
if (!target) throw new Error('Invalid target platform');
opts.targetPlatform = options.targetPlatform;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/platforms/TargetPlatform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default class TargetPlatform {
private id: string;
private printableName: string;
id: string;
printableName: string;

constructor(id: string, printableName: string) {
this.id = id;
Expand Down
10 changes: 4 additions & 6 deletions src/utils/platforms/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { isKeyOfObject } from '../types';

import TargetPlatform from './TargetPlatform';
import { TargetPlatforms } from './TargetPlatforms';
import { isKeyOfObject } from '../types';

export function getTargetById(id?: string | null) {
const key = id && id.toUpperCase();
return key && isKeyOfObject(key, TargetPlatforms)
? TargetPlatforms[key]
: TargetPlatforms.JAVA;
const key = id && id.toUpperCase().replace(/-/g, '_');

return isKeyOfObject(key, TargetPlatforms) ? TargetPlatforms[key] : null;
}

export function isJavaRelated(platform: TargetPlatform) {
Expand Down

0 comments on commit bb31ed5

Please sign in to comment.