ts-loader icon indicating copy to clipboard operation
ts-loader copied to clipboard

AngularJS 1.5 pattern escape problem

Open jamesbcn opened this issue 2 years ago • 6 comments

Bug report

Webpack version: 5.75.0 TS-Loader version: 9.4.1 Please tell us about your environment: Windows 10

Current behavior: I am migrating AngularJS, and some inputs have ng-pattern attribute. TS-Loader removes backslashes in regex inside this attribute and because of this regex is not valid. In my code I have ng-pattern="/^\+[\d]{7,15}$/" and output is ng-pattern="/^\+[\d]{7,15}$/"

The same problem was reported and fixed in HTML-Loader here

Expected/desired behavior: Please add regex processing.

tsconfig.json { "compilerOptions": { "baseUrl": "", "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": ["es6", "dom"], "mapRoot": "./", "module": "es6", "moduleResolution": "node", "outDir": "../dist/out-tsc", "sourceMap": true, "target": "es5", "typeRoots": [ "./node_modules/@types" ] } }

webpack.config.js module.exports = { entry: "./app/main.ts", output: { filename: "src/dist/bundle.js" }, resolve: { // Add '.ts' and '.tsx' as a resolvable extension. extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"] }, module: { rules: [ // all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader' { test: /\.tsx?$/, loader: "ts-loader" } ] }, optimization:{ minimize: false } };

jamesbcn avatar Nov 18 '22 19:11 jamesbcn

ts-loader handles TypeScript - it doesn't handle templates; I'm not sure where you'd do this, but probably not in ts-loader

johnnyreilly avatar Nov 18 '22 19:11 johnnyreilly

OK. I have reported it to Webpack: https://github.com/webpack/webpack/issues/16488

Thanks.

jamesbcn avatar Nov 18 '22 20:11 jamesbcn

They are saying the same. It is not their issue but a loader issue.

Ts-loader is the only loader I am using and the HTML is inline within the .ts files...

jamesbcn avatar Nov 23 '22 17:11 jamesbcn

ts-loader doesn't directly process TS files - that is handled by TypeScript itself. I wonder if you can manually escape your regexes to get around this issue

johnnyreilly avatar Nov 23 '22 17:11 johnnyreilly

Given angular js is end of life you may want to think about migration away from it https://en.m.wikipedia.org/wiki/AngularJS

johnnyreilly avatar Nov 23 '22 17:11 johnnyreilly

Manually escaping should work - it's just a lot of work.

And yeah, I'm in the process of migrating. First step was to switch to Typescript.

jamesbcn avatar Nov 23 '22 21:11 jamesbcn