ether-code 0.6.5 → 0.6.7

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.
@@ -1023,32 +1023,52 @@ class HTMLGenerator {
1023
1023
  const lowerCode = code.toLowerCase()
1024
1024
  const hasEtherKeywords = etherKeywords.some(kw => lowerCode.includes(kw))
1025
1025
 
1026
- if (!hasEtherKeywords) {
1027
- return code
1028
- }
1029
-
1030
- if (tagType === 'script' && this.parser && this.jsGenerator) {
1031
- try {
1032
- const ast = this.parser.parse(code, 'js')
1033
- const generated = this.jsGenerator.generate(ast)
1034
- return generated || code
1035
- } catch (e) {
1036
- return code
1026
+ if (tagType === 'script') {
1027
+ if (hasEtherKeywords && this.parser && this.jsGenerator) {
1028
+ try {
1029
+ const ast = this.parser.parse(code, 'js')
1030
+ const generated = this.jsGenerator.generate(ast)
1031
+ return generated || code
1032
+ } catch (e) {
1033
+ return this.addSemicolons(code)
1034
+ }
1037
1035
  }
1036
+ return this.addSemicolons(code)
1038
1037
  }
1039
1038
 
1040
- if (tagType === 'style' && this.parser && this.cssGenerator) {
1041
- try {
1042
- const ast = this.parser.parse(code, 'css')
1043
- const generated = this.cssGenerator.generate(ast)
1044
- return generated || code
1045
- } catch (e) {
1046
- return code
1039
+ if (tagType === 'style') {
1040
+ if (hasEtherKeywords && this.parser && this.cssGenerator) {
1041
+ try {
1042
+ const ast = this.parser.parse(code, 'css')
1043
+ const generated = this.cssGenerator.generate(ast)
1044
+ return generated || code
1045
+ } catch (e) {
1046
+ return code
1047
+ }
1047
1048
  }
1049
+ return code
1048
1050
  }
1049
1051
 
1050
1052
  return code
1051
1053
  }
1054
+
1055
+ addSemicolons(code) {
1056
+ const lines = code.split('\n')
1057
+ const result = lines.map(line => {
1058
+ const trimmed = line.trim()
1059
+ if (!trimmed) return line
1060
+ const lastChar = trimmed.slice(-1)
1061
+ const noSemicolonEndings = [';', '{', '}', ',', ':', '(', '[']
1062
+ if (noSemicolonEndings.includes(lastChar)) {
1063
+ return line
1064
+ }
1065
+ if (trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*')) {
1066
+ return line
1067
+ }
1068
+ return line + ';'
1069
+ })
1070
+ return result.join('\n')
1071
+ }
1052
1072
  }
1053
1073
 
1054
1074
  module.exports = {