eemeli/fluent-compiler

Default variant is not being transpiled properly

Opened this issue · 2 comments

Hi,

I'm trying to use this compiler in my build process. With the demo ftl source in README.md, when trying to display the sync-dialog-title (which references another key), I get an exception ($.capitalization, can't access property capitalization of undefined). Seeing the generated ouput I feel that maybe in sync-dialog-title the call to value() should be value({}) so that the call does not throw, but not really sure.

Anyway great work, I would guess that messageformat is a more established tool, but fluent also looks promising as long as we can rely on build time tools like this one.

Thanks!

Germán

output:

import Runtime from "fluent-compiler/runtime"
const { bundle, isol, select } = Runtime("es")
const R = new Map([

["-sync-brand-name", { value: $ => [select($.capitalization, "uppercase", { uppercase: "Account Firefox", lowercase: "account Firefox" })] }],
["sync-dialog-title", { value: $ => [R.get("-sync-brand-name").value()] }],
["sync-headline-title", { value: $ => [isol(R.get("-sync-brand-name").value()), ": il modo migliore\nper avere i tuoi dati sempre con te"] }],
// Explicitly request the lowercase variant of the brand name.
["sync-signedout-account-title", { value: $ => ["Connetti il tuo ", isol(R.get("-sync-brand-name").value({ capitalization: "lowercase" }))] }],
["welcome", { value: $ => ["Hi how are you!!"] }],

])
export const resource = R
export default bundle(R)

input

-sync-brand-name = {$capitalization ->
   *[uppercase] Account Firefox
    [lowercase] account Firefox
}

sync-dialog-title = {-sync-brand-name}
sync-headline-title =
    {-sync-brand-name}: il modo migliore
    per avere i tuoi dati sempre con te

# Explicitly request the lowercase variant of the brand name.
sync-signedout-account-title =
    Connetti il tuo {-sync-brand-name(capitalization: "lowercase")}

welcome = 
    Hi how are you!!

@germanftorres

Just calling.value({}) doesn't seem to really solve the issue here apart of silencing the error. How one could pass the correct capitalization value (uppercase/lowercase in this example) if the value used is always an empty object?

I'll dig a bit more into the compiler code to see if I can shed some light in this issue as well understand more how the compiled code with selectors is supposed to be used/generated.

@eemeli
Is this related to this comment on one of the tests for select expressions?

https://github.com/eemeli/fluent-compiler/blob/master/test/select_expressions.test.js#L27

I'm trying to figure it out how to avoid the undefined reference without breaking any API