diff --git a/src/executable-code/index.js b/src/executable-code/index.js index 3714563..0c3ee68 100644 --- a/src/executable-code/index.js +++ b/src/executable-code/index.js @@ -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"; diff --git a/src/lib/crosslink.ts b/src/lib/crosslink.ts index 651e2e8..6bf70ac 100644 --- a/src/lib/crosslink.ts +++ b/src/lib/crosslink.ts @@ -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, @@ -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; } diff --git a/src/utils/platforms/TargetPlatform.ts b/src/utils/platforms/TargetPlatform.ts index 2731dab..d6298cc 100644 --- a/src/utils/platforms/TargetPlatform.ts +++ b/src/utils/platforms/TargetPlatform.ts @@ -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; diff --git a/src/utils/platforms/index.ts b/src/utils/platforms/index.ts index 602e794..c60ee7d 100644 --- a/src/utils/platforms/index.ts +++ b/src/utils/platforms/index.ts @@ -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) {