Skip to content

Commit

Permalink
Use jsStringEscape for better back slash handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Mar 29, 2021
1 parent 0838550 commit 2ac6e44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ let d = w.define;
{{#if styles}}
if (macroCondition(!getGlobalConfig().fastboot?.isRunning)) {
{{#each styles as |stylePath| ~}}
i("{{stylePath.path}}");
i("{{js-string-escape stylePath.path}}");
{{/each}}
}
{{/if}}
Expand Down
29 changes: 15 additions & 14 deletions packages/core/src/template-compiler-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import { join, sep } from 'path';
import type { PluginItem } from '@babel/core';
import { Memoize } from 'typescript-memoize';
import wrapLegacyHbsPluginIfNeeded from 'wrap-legacy-hbs-plugin-if-needed';
<<<<<<< HEAD:packages/core/src/template-compiler-common.ts
||||||| parent of 5bf3fe4a (Use jsStringEscape for better back slash handling):packages/core/src/template-compiler.ts
import { patch } from './patch-template-compiler';
import { Portable, PortableHint } from './portable';
import type { Params as InlineBabelParams } from './babel-plugin-inline-hbs';
import { createContext, Script } from 'vm';
=======
import { patch } from './patch-template-compiler';
import { Portable, PortableHint } from './portable';
import type { Params as InlineBabelParams } from './babel-plugin-inline-hbs';
import { createContext, Script } from 'vm';
import jsStringEscape from 'js-string-escape';
>>>>>>> 5bf3fe4a (Use jsStringEscape for better back slash handling):packages/core/src/template-compiler.ts

export interface Plugins {
ast?: unknown[];
Expand Down Expand Up @@ -303,22 +316,10 @@ export function templateCompilerModule(params: TemplateCompilerParams, hints: Po
let p = new Portable({ hints });
let result = p.dehydrate(params);

let escapedCompilerPath = __filename;
let portablePath = resolve(__dirname, './portable.js');

if (__filename.includes('\\')) {
// for windows this path will look something like:
// C:\foo\bar\baz however because of the back slashes this
// does not escape correctly. Therefor we need to replace the
// path to: C:\\foo\\bar\\baz
escapedCompilerPath = escapedCompilerPath.replace(/\\/g, '\\\\');
portablePath = portablePath.replace(/\\/g, '\\\\');
}

return {
src: [
`const { TemplateCompiler } = require("${escapedCompilerPath}");`,
`const { Portable } = require("${portablePath}");`,
`const { TemplateCompiler } = require("${jsStringEscape(__filename)}");`,
`const { Portable } = require("${jsStringEscape(resolve(__dirname, './portable.js'))}");`,
`let p = new Portable({ hints: ${JSON.stringify(hints, null, 2)} });`,
`module.exports = new TemplateCompiler(p.hydrate(${JSON.stringify(result.value, null, 2)}))`,
].join('\n'),
Expand Down

0 comments on commit 2ac6e44

Please sign in to comment.