From bd1dd92cf8fb353f97d577e52b8f9d37132ef082 Mon Sep 17 00:00:00 2001 From: Rory Date: Sun, 22 Aug 2021 09:49:52 +1000 Subject: [PATCH] Allow compiler language selection via query parameter, fixes #1489 --- apps/remix-ide-e2e/src/tests/url.spec.ts | 3 ++- .../solidity-compiler/src/lib/compiler-container.tsx | 9 ++++++--- .../solidity-compiler/src/lib/logic/compileTabLogic.ts | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/url.spec.ts b/apps/remix-ide-e2e/src/tests/url.spec.ts index 9d7e8e323e..13227238f7 100644 --- a/apps/remix-ide-e2e/src/tests/url.spec.ts +++ b/apps/remix-ide-e2e/src/tests/url.spec.ts @@ -77,12 +77,13 @@ module.exports = { 'Should load using URL compiler params': function (browser: NightwatchBrowser) { browser .pause(5000) - .url('http://127.0.0.1:8080/#optimize=true&runs=300&autoCompile=true&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js') + .url('http://127.0.0.1:8080/#optimize=true&runs=300&autoCompile=true&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js&language=Yul') .refresh() .pause(5000) .clickLaunchIcon('solidity') .assert.containsText('#versionSelector option[data-id="selected"]', '0.7.4+commit.3f05b770') .assert.containsText('#evmVersionSelector option[data-id="selected"]', 'istanbul') + .assert.containsText('#compilierLanguageSelector option[data-id="selected"]', 'Yul') .verify.elementPresent('#optimize:checked') .verify.elementPresent('#autoCompile:checked') .verify.attributeEquals('#runs', 'value', '300') diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index eabccbd8a8..f1b88e90a1 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -7,6 +7,7 @@ import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL, promi import { compilerReducer, compilerInitialState } from './reducers/compiler' import { resetEditorMode, listenToEvents } from './actions/compiler' import { OverlayTrigger, Tooltip } from 'react-bootstrap' // eslint-disable-line +import { helpers } from '@remix-project/remix-lib' import './css/style.css' @@ -74,6 +75,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const optimize = params.optimize const runs = params.runs as string const evmVersion = params.evmVersion + const language = helpers.compiler.getValidLanguage(params.language) return { ...prevState, @@ -82,7 +84,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => { includeNightlies: includeNightlies, optimize: optimize, runs: runs, - evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default' + evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default', + language: (language !== null) ? language : 'Solidity' } }) } @@ -537,8 +540,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
diff --git a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts index c938cdb633..db24685e3a 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts @@ -15,6 +15,7 @@ export class CompileTabLogic { public optimize public runs public evmVersion: string + public language: string public compilerImport public event @@ -39,6 +40,13 @@ export class CompileTabLogic { } this.api.setCompilerParameters({ evmVersion: this.evmVersion }) this.compiler.set('evmVersion', this.evmVersion) + + this.language = this.api.getParameters().language + if(this.language === 'undefined' || this.language === 'null' || !this.language) { + this.language = null + } + this.api.setParameters({ 'language': this.language }) + this.compiler.set('language', this.language) } setOptimize (newOptimizeValue) { @@ -68,6 +76,8 @@ export class CompileTabLogic { * @params lang {'Solidity' | 'Yul'} ... */ setLanguage (lang) { + this.language = lang; + this.api.setParameters({ language: lang }) this.compiler.set('language', lang) }