Adding helper method for checking compiler language before setting

allow-url-language-selection
Rory 3 years ago committed by yann300
parent bd1dd92cf8
commit 5661717ce6
  1. 12
      libs/remix-lib/src/helpers/compilerHelper.ts
  2. 29
      libs/remix-lib/test/compilerHelper.ts
  3. 1
      libs/remix-lib/test/tests.ts
  4. 13
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

@ -1,3 +1,5 @@
import {Language} from "@remix-project/remix-solidity-ts";
export function compilerInput (contracts) {
return JSON.stringify({
language: 'Solidity',
@ -20,3 +22,13 @@ export function compilerInput (contracts) {
}
})
}
export const Languages = ['Solidity', 'Yul']
export function getValidLanguage (val: string): Language {
if (val !== undefined && val !== null && val) {
const lang = val.slice(0, 1).toUpperCase() + val.slice(1).toLowerCase()
return Languages.indexOf(lang) > -1 ? lang as Language : null
}
return null
}

@ -0,0 +1,29 @@
'use strict'
import tape from 'tape'
import { getValidLanguage } from "../src/helpers/compilerHelper";
import { Language } from "@remix-project/remix-solidity-ts";
tape('compilerHelper', function (t) {
t.test('lowerbound', function (st) {
st.plan(9)
const correctYul: Language = 'Yul';
const correctSolidity: Language = 'Solidity';
const yulUpperCase = 'Yul'
const yulLowerCase = 'yul'
const solidityUpperCase = 'Solidity'
const solidityLowerCase = 'solidity'
st.equal(getValidLanguage(yulLowerCase), correctYul)
st.equal(getValidLanguage(yulUpperCase), correctYul)
st.equal(getValidLanguage(solidityUpperCase), correctSolidity)
st.equal(getValidLanguage(solidityLowerCase), correctSolidity)
st.equal(getValidLanguage(null), null)
st.equal(getValidLanguage(undefined), null)
st.equal(getValidLanguage(''), null)
st.equal(getValidLanguage('A'), null)
st.equal(getValidLanguage('Something'), null)
})
})

@ -3,3 +3,4 @@ require('./util.ts')
require('./txFormat.ts')
require('./txHelper.ts')
require('./txResultHelper.ts')
require('./compilerHelper.ts')

@ -1,4 +1,5 @@
import { ICompilerApi } from '@remix-project/remix-lib-ts'
import { helpers } from '@remix-project/remix-lib'
const Compiler = require('@remix-project/remix-solidity').Compiler
const EventEmitter = require('events')
@ -41,12 +42,10 @@ 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.language = helpers.compiler.getValidLanguage(this.api.getCompilerParameters().language)
if (this.language != null) {
this.compiler.set('language', this.language)
}
this.api.setParameters({ 'language': this.language })
this.compiler.set('language', this.language)
}
setOptimize (newOptimizeValue) {
@ -76,8 +75,8 @@ export class CompileTabLogic {
* @params lang {'Solidity' | 'Yul'} ...
*/
setLanguage (lang) {
this.language = lang;
this.api.setParameters({ language: lang })
this.language = lang
this.api.setCompilerParameters({ language: lang })
this.compiler.set('language', lang)
}

Loading…
Cancel
Save