fluent-transpiler 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -82,7 +82,7 @@ export const compile = (src, opts) => {
82
82
  Term: (data) => {
83
83
  const assignment = compileAssignment(data.id)
84
84
  const templateStringLiteral = compileType(data.value)
85
- metadata[variable].term = true
85
+ metadata[assignment].term = true
86
86
  if (metadata[assignment].params) {
87
87
  return `const ${assignment} = (${options.params}) => ${templateStringLiteral}\n`
88
88
  }
@@ -185,14 +185,25 @@ export const compile = (src, opts) => {
185
185
  },
186
186
  TermReference: (data) => {
187
187
  const termName = compileType(data.id)
188
- const {named} = compileFunctionArguments(data)
188
+ metadata[variable].params ||= metadata[termName].params
189
+
190
+ let params
191
+ if (metadata[termName].params) {
192
+ let {named} = compileFunctionArguments(data)
193
+ named = JSON.stringify(named)
194
+ if (named) {
195
+ params = `{ ...${options.params}, ${named.substring(1, named.length-1)} }`
196
+ } else {
197
+ params = options.params
198
+ }
199
+ }
189
200
  if (!options.disableMinify) {
190
201
  if (metadata[termName].params) {
191
- return `${termName}(${JSON.stringify(named)})`
202
+ return `${termName}(${params})`
192
203
  }
193
204
  return `${termName}`
194
205
  }
195
- return `${termName}(${named ? JSON.stringify(named) : ''})`
206
+ return `${termName}(${params ? params : ''})`
196
207
  },
197
208
  NamedArgument:(data) => {
198
209
  // Inconsistent: `NamedArgument` uses `name` instead of `id` for Identifier
@@ -245,7 +256,6 @@ export const compile = (src, opts) => {
245
256
  }
246
257
 
247
258
  const {body} = parse(src)
248
-
249
259
  let translations = ``
250
260
  for(const data of body) {
251
261
  translations += compileType(data)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluent-transpiler",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "Transpile Fluent (ftl) files into optomized, tree-shakable, JavaScript EcmaScript Modules (esm).",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,6 +15,10 @@ replaceTerm = term: { -term }.
15
15
  }
16
16
  parameterized-terms = Informacje o { -brand-name(case: "locative") }.
17
17
 
18
+
19
+ -term-with-var = {$number}
20
+ termWithVariable = {-term-with-var}
21
+
18
22
  ### Message References
19
23
  messageValue = message: { replaceTerm }
20
24
  messageNestedParamValue = message: { replaceParam }
@@ -105,6 +109,8 @@ selectorNumberOrdinal =
105
109
  *[other] There are { $number } (other).
106
110
  }
107
111
 
112
+ subSelector = {selectorNumberOrdinal}
113
+
108
114
  ## Attributes
109
115
  loginInput = Predefined value
110
116
  .placeholder = email@example.com
@@ -33,7 +33,9 @@ const brandName = (params) => `${__select(
33
33
  },
34
34
  `Firefox`
35
35
  )}`
36
- export const parameterizedTerms = `Informacje o ${brandName({"case":"locative"})}.`
36
+ export const parameterizedTerms = (params) => `Informacje o ${brandName({ ...params, "case":"locative" })}.`
37
+ const termWithVar = (params) => `${params?.number}`
38
+ export const termWithVariable = (params) => `${termWithVar(params)}`
37
39
  // ### Message References
38
40
  export const messageValue = `message: ${replaceTerm}`
39
41
  export const messageNestedParamValue = (params) => `message: ${replaceParam(params)}`
@@ -96,6 +98,7 @@ export const selectorNumberOrdinal = (params) => `${__select(
96
98
  },
97
99
  `There are ${__formatVariable(params?.number)} (other).`
98
100
  )}`
101
+ export const subSelector = (params) => `${selectorNumberOrdinal(params)}`
99
102
  // ## Attributes
100
103
  export const loginInput = {
101
104
  value: `Predefined value`,
@@ -112,7 +115,7 @@ ${".attr = Value"} on a new line.`,
112
115
  attr: `An actual attribute (not part of the text value above)`
113
116
  }
114
117
  }
115
- const __exports = {text, replaceParam, replaceTerm, 'parameterized-terms':parameterizedTerms, messageValue, messageNestedParamValue, openingBrace, closingBrace, blankIsRemoved, blankIsPreserved, leadingBracket, literalQuote, literalEscapedQuote, privacyLabel, dash, dashUnicode, emoji, emojiUnicode, singleLine, multiLine, block, leadingBlankSpaces, leadingBlankLines, blankLines, multiLineIndent, timeElapsed, todayIs, selectorNumberCardinal, selectorNumberOrdinal, loginInput, attributeHowTo}
118
+ const __exports = {text, replaceParam, replaceTerm, 'parameterized-terms':parameterizedTerms, termWithVariable, messageValue, messageNestedParamValue, openingBrace, closingBrace, blankIsRemoved, blankIsPreserved, leadingBracket, literalQuote, literalEscapedQuote, privacyLabel, dash, dashUnicode, emoji, emojiUnicode, singleLine, multiLine, block, leadingBlankSpaces, leadingBlankLines, blankLines, multiLineIndent, timeElapsed, todayIs, selectorNumberCardinal, selectorNumberOrdinal, subSelector, loginInput, attributeHowTo}
116
119
 
117
120
  export default (id, params) => {
118
121
  const source = __exports[id] ?? __exports['_'+id]