E118
Error
Syntax and structure
E118 — A name the language already has
A name the language gives a meaning cannot be a program's own — not a state, derived, persist or let, a prop, a route or action parameter, a loop item, a lambda's parameter, a binding of if let, match or a slot, nor a top-level const, data, image, store or api. They are env, the build's settings; params, the route's; locale and dir, the reader's language; the values the browser keeps current, now, viewport, query, hash, theme, network and update; the language's functions (t, format, ago, log, navigate, fetch, uuid, sanitize, every, after, …); the words a statement is written with (state, action, let, if, show, match, style, on, …); and, at the top level, the runtime's WF. Declared, one would hide what the language means by it for as far as its scope reaches. The names a handler brings (event, e, value, key) and the browser's globals are a program's to use.
What the compiler said
error[E118]: `env` is a name the language already has: the build's settings, read as `env.PUBLIC_API` --> src/App.wf:2:5 | 2 | state env = "staging" | ^^^^^^^^^^^^^^^^^^^^^ = help: Name it something of your own — `target` or `stage`: inside its scope every `env` would mean this, and the language's would have no name = docs: https://webfluent.monzeromer.dev/errors/E118
The fix
Broken
page Deploy(path: "/", title: "Deploy", description: "Pick a target.") {
state env = "staging"
Heading("Deploy to {env}").h1
}
Fixed
page Deploy(path: "/", title: "Deploy", description: "Pick a target.") {
state target = "staging"
Heading("Deploy to {target}").h1
}
Name it something of your own — state target = "staging" — and
its reads with it. The message suggests one where there is a usual choice:
target or stage for env, search for query, scheme for theme,
item or a word for what it holds for t.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
A name the language gives a meaning is not a program's to declare — not as
a state, derived, persist or let, a prop, a route or action
parameter, a loop item, a lambda's parameter, a binding of if let, match
or a slot, nor a top-level const, data, image, store or api.
Declared, it would hide what the language means by it for as far as its
scope reaches: a state env hid the build's settings in its page, and a
loop's t hid the translation function inside the loop. The names are:
env, the build's settings;params, the route's;localeanddir,
the reader's language;
- the values the browser keeps current:
now,viewport,query,hash,
theme, network, update;
- the language's functions:
t,format,ago,log,navigate,
fetch, uuid, sanitize, setLocale, setTheme, optimistic,
beacon, animate, replayAnimation, every, after, ws, sse,
broadcast, rtc;
- the words a statement is written with:
state,persist,derived,
effect, action, use, resource, validate, socket, stream,
channel, peer, head, slot, part, if, else, for, in, by,
show, match, children, emit, sequence, on, style,
transition, let, return, await, try, catch;
- at the top level,
WF, the runtime the compiled pages call; - in a store, the names every JavaScript object has —
valueOf,
toString, constructor, hasOwnProperty, isPrototypeOf,
propertyIsEnumerable, toLocaleString, __proto__ and its
__define…/__lookup… kin: a store is an object whose members are its
own, and a valueOf member replaced the one JavaScript calls itself, so
the page threw as soon as it was drawn;
- and, as a prop,
__proto__, which in the object a call passes sets its
prototype instead (a prop named toString or valueOf is fine).
The names a handler brings with it — event, e, value, key — and the
browser's globals (window, history, …) are a program's to use, and so is
any name as a field, a map key or an enum case: type Box { env: String }
and .env are fine.
lints cannot lower it: it would ship a broken page.