Skip to content

Disable declaration-shadowing warning on transpiled JsLIGO contracts

Nicolas Phan requested to merge transpile_option_2 into dev

Motivation and Context

Re-declaring a block-scoped variable is forbidden in JsLIGO. This rule is enforced with a "jsligo-shadowing" check.

However, this situation can appear on JsLIGO contracts resulting from transpilation, from another syntax allowing shadowing of variable.

In that case, we want to disable the "jsligo-shadowing" check for transpiled contracts.

This MR introduces the --transpiled flag, allowing the user to specify that a contract comes from transpilation. It also disables the jsligo-shadowing check when the --transpiled flag is given.

Description

Component

  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

For a JsLIGO contracts with re-declared variables, like the following, with x re-declared :

const x = 42;
const x = 33;

const main = ([_action, store] : [int, int]) : [list <operation>, int] => {
 return [
   (list([]) as list <operation>),    // No operations
   store
  ]
};

Compilation will throw the following error :

> ligo compile contract 'transpile_warn_shadowing.jsligo'
File "transpile_warn_shadowing.jsligo", line 2, characters 10-12:
 11 | const x = 42;
 12 | const x = 33;
 13 | 

Cannot redeclare block-scoped variable. 

Compilation using the --transpiled flag will disable the warning.

Before

> ligo compile contract 'transpile_warn_shadowing.jsligo' --transpiled
Error parsing command line:

  unknown flag --transpiled

For usage information, run

  ligo compile contract -help

After

> ligo compile contract 'transpile_warn_shadowing.jsligo' --transpiled
{ parameter int ; storage int ; code { CDR ; NIL operation ; PAIR } }

Checklist:

  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).

Merge request reports