Merge pull request #1504 from rorye/allow-url-language-selection

Allow compiler language selection via query parameter, fixes #1489
pull/1948/head^2
David Disu 3 years ago committed by GitHub
commit 0845d5fa0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      apps/remix-ide-e2e/src/tests/url.spec.ts
  2. 24
      libs/remix-solidity/jest.config.js
  3. 1
      libs/remix-solidity/package.json
  4. 12
      libs/remix-solidity/src/compiler/compiler-input.ts
  5. 2
      libs/remix-solidity/src/index.ts
  6. 25
      libs/remix-solidity/tests/compiler-input.spec.ts
  7. 2
      libs/remix-solidity/tsconfig.json
  8. 9
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  9. 9
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  10. 6
      workspace.json

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

@ -0,0 +1,24 @@
module.exports = {
name: 'remix-solidity',
preset: '../../jest.config.js',
verbose: true,
silent: false, // Silent console messages, specially the 'remix-simulator' ones
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
transformIgnorePatterns: ["/node_modules/", "/dist/", "\\.pnp\\.[^\\\/]+$"],
rootDir: "./",
testTimeout: 40000,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html', 'json'],
// Coverage
collectCoverage: true,
coverageReporters: ['text', 'text-summary'],
collectCoverageFrom: [
"**/*.ts",
"!**/sol/**",
"!src/types.ts",
"!src/logger.ts"
],
coverageDirectory: '../../coverage/libs/remix-solidity'
};

@ -41,7 +41,6 @@
"@types/node": "^13.1.1",
"babel-eslint": "^10.0.0",
"babelify": "^10.0.0",
"tape": "^4.6.0",
"typescript": "^3.7.4"
},
"scripts": {

@ -1,6 +1,6 @@
'use strict'
import { CompilerInput, Source, CompilerInputOptions } from './types'
import { CompilerInput, Source, CompilerInputOptions, Language } from './types'
export default (sources: Source, opts: CompilerInputOptions): string => {
const o: CompilerInput = {
@ -32,3 +32,13 @@ export default (sources: Source, opts: CompilerInputOptions): string => {
}
return JSON.stringify(o)
}
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
}

@ -1,6 +1,6 @@
export { Compiler } from './compiler/compiler'
export { compile } from './compiler/compiler-helpers'
export { default as CompilerInput } from './compiler/compiler-input'
export { default as CompilerInput, getValidLanguage } from './compiler/compiler-input'
export { CompilerAbstract } from './compiler/compiler-abstract'
export * from './compiler/types'
export { promisedMiniXhr, pathToURL, baseURLBin, baseURLWasm, canUseWorker, urlFromVersion } from './compiler/compiler-utils'

@ -0,0 +1,25 @@
import { getValidLanguage } from '../src/compiler/compiler-input'
import { Language } from '../src/compiler/types'
describe('compiler-input', () => {
test('getValidLanguage', () => {
const correctYul: Language = 'Yul'
const correctSolidity: Language = 'Solidity'
const yulUpperCase = 'Yul'
const yulLowerCase = 'yul'
const solidityUpperCase = 'Solidity'
const solidityLowerCase = 'solidity'
expect(getValidLanguage(yulLowerCase)).toBe(correctYul)
expect(getValidLanguage(yulUpperCase)).toBe(correctYul)
expect(getValidLanguage(solidityUpperCase)).toBe(correctSolidity)
expect(getValidLanguage(solidityLowerCase)).toBe(correctSolidity)
expect(getValidLanguage(null)).toBe(null)
expect(getValidLanguage(undefined)).toBe(null)
expect(getValidLanguage('')).toBe(null)
expect(getValidLanguage('A')).toBe(null)
expect(getValidLanguage('Something')).toBe(null)
})
})

@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node"]
"types": ["jest", "node"]
},
"include": ["**/*.ts"]
}

@ -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 { getValidLanguage } from '@remix-project/remix-solidity'
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 = 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">

@ -1,4 +1,5 @@
import { ICompilerApi } from '@remix-project/remix-lib-ts'
import { getValidLanguage } from '@remix-project/remix-solidity'
const Compiler = require('@remix-project/remix-solidity').Compiler
const EventEmitter = require('events')
@ -15,6 +16,7 @@ export class CompileTabLogic {
public optimize
public runs
public evmVersion: string
public language: string
public compilerImport
public event
@ -39,6 +41,11 @@ export class CompileTabLogic {
}
this.api.setCompilerParameters({ evmVersion: this.evmVersion })
this.compiler.set('evmVersion', this.evmVersion)
this.language = getValidLanguage(this.api.getCompilerParameters().language)
if (this.language != null) {
this.compiler.set('language', this.language)
}
}
setOptimize (newOptimizeValue) {
@ -68,6 +75,8 @@ export class CompileTabLogic {
* @params lang {'Solidity' | 'Yul'} ...
*/
setLanguage (lang) {
this.language = lang
this.api.setCompilerParameters({ language: lang })
this.compiler.set('language', lang)
}

@ -309,10 +309,10 @@
}
},
"test": {
"builder": "@nrwl/workspace:run-commands",
"builder": "@nrwl/jest:jest",
"options": {
"commands": ["./../../node_modules/.bin/npm-run-all test"],
"cwd": "libs/remix-solidity"
"jestConfig": "libs/remix-solidity/jest.config.js",
"tsConfig": "libs/remix-solidity/tsconfig.spec.json"
}
},
"build": {

Loading…
Cancel
Save