Allow compiler language selection via query parameter, fixes #1489

allow-url-language-selection
Rory 3 years ago committed by yann300
parent 15c0033345
commit bd1dd92cf8
  1. 3
      apps/remix-ide-e2e/src/tests/url.spec.ts
  2. 9
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  3. 10
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.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')

@ -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) => {
<div className="mb-2">
<label className="remixui_compilerLabel form-check-label" htmlFor="compilierLanguageSelector">Language</label>
<select onChange={(e) => handleLanguageChange(e.target.value)} value={state.language} className="custom-select" id="compilierLanguageSelector" title="Available since v0.5.7">
<option value='Solidity'>Solidity</option>
<option value='Yul'>Yul</option>
<option data-id={state.language === 'Solidity' ? 'selected' : ''} value='Solidity'>Solidity</option>
<option data-id={state.language === 'Yul' ? 'selected' : ''} value='Yul'>Yul</option>
</select>
</div>
<div className="mb-2">

@ -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)
}

Loading…
Cancel
Save