# wxml/no-const-and-let-in-wxs

# Background

let and const

let and const not work in wxs (opens new window)

Concepts In WXS, all variables reference values.

  • Undeclared variables that use directly assigned values are defined as global variables.
  • If you declare a variable but do not assign a value, its default value is undefined.
  • The var performance is consistent with JavaScript and variable hoisting is performed.

Wechat Document Reference (opens new window)

# Motivation

This rule hint wechat miniprogram developer don't using let and const in wxs.

<!-- ✓ GOOD --> <wxs module="util" > var s = 100; module.exports = { data: s } </wxs> <!-- ✗ BAD --> <wxs module="util" > let s = 100; const k = {}; module.exports = { data: s, obj: k } </wxs>
Now loading...

💡 tips

You can edit code via online editor, it's online REPL, try to fix eslint problem !

# Config

No special options, normal config is ok

{ "wxml/no-const-and-let-in-wxs": "error" }

# Version

This rule was introduced in eslint-plugin-wxml v0.2.1

# Implementation