fluent-transpiler 0.1.3 → 0.2.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.
Files changed (2) hide show
  1. package/index.js +11 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -68,8 +68,15 @@ export const compile = (src, opts) => {
68
68
  }
69
69
 
70
70
  const types = {
71
- Identifier: (data) => {
72
- const value = variableNotation[options.variableNotation](data.name)
71
+ Identifier: (data, parent) => {
72
+ const value =
73
+ parent === 'Attribute'
74
+ ? data.name
75
+ : variableNotation[options.variableNotation](data.name)
76
+
77
+ if (value.includes('-')) {
78
+ return `'${value}'`
79
+ }
73
80
  // Check for reserved words - TODO add in rest
74
81
  if (['const', 'default', 'enum', 'if'].includes(value)) {
75
82
  return '_' + value
@@ -77,7 +84,7 @@ export const compile = (src, opts) => {
77
84
  return value
78
85
  },
79
86
  Attribute: (data) => {
80
- const key = compileType(data.id)
87
+ const key = compileType(data.id, data.type)
81
88
  const value = compileType(data.value, data.type)
82
89
  return ` ${key}: ${value}`
83
90
  },
@@ -195,7 +202,7 @@ export const compile = (src, opts) => {
195
202
  },
196
203
  // Element
197
204
  TextElement: (data) => {
198
- return data.value
205
+ return data.value.replaceAll('`', '\\`') // escape string literal
199
206
  },
200
207
  Placeable: (data, parent) => {
201
208
  return `${options.useIsolating ? '\u2068' : ''}\${${compileType(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluent-transpiler",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "Transpile Fluent (ftl) files into optimized, tree-shakable, JavaScript EcmaScript Modules (esm).",
5
5
  "main": "index.js",
6
6
  "type": "module",