From b3d9de4b926a23e016d12b077df6381984151387 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 16 Jun 2023 18:58:24 +0200 Subject: [PATCH 1/2] failing test --- src/utils/sourcemaps/inject.rs | 40 ++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index b0cd91c5c8..22d813b2a9 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -516,7 +516,7 @@ something else //# sourceMappingURL=fake1 // some other comment - "use strict"; rest of the line +"use strict"; rest of the line 'use strict'; some line //# sourceMappingURL=fake2 @@ -533,7 +533,7 @@ something else"#; //# sourceMappingURL=fake1 // some other comment - "use strict"; rest of the line +"use strict"; rest of the line 'use strict'; !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); some line @@ -546,6 +546,42 @@ something else assert_eq!(std::str::from_utf8(&source).unwrap(), expected); } + #[test] + fn test_fixup_js_file_fake_use_strict() { + let source = r#"#!/bin/node +//# sourceMappingURL=fake1 + + // some other comment +"use strict"; rest of the line +(this.foo=this.bar||[]).push([[2],[function(e,t,n){"use strict"; […] } +some line +//# sourceMappingURL=fake2 +//# sourceMappingURL=real +something else"#; + + let debug_id = DebugId::default(); + + let mut source = Vec::from(source); + + fixup_js_file(&mut source, debug_id).unwrap(); + + let expected = r#"#!/bin/node +//# sourceMappingURL=fake1 + + // some other comment +"use strict"; rest of the line +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); +(this.foo=this.bar||[]).push([[2],[function(e,t,n){"use strict"; […] } +some line +//# sourceMappingURL=fake2 +something else +//# debugId=00000000-0000-0000-0000-000000000000 +//# sourceMappingURL=real +"#; + + assert_eq!(std::str::from_utf8(&source).unwrap(), expected); + } + #[test] fn test_normalize_sourcemap_url() { assert_eq!( From eb99351e0ca626f13da686981f620f545f2efc55 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 16 Jun 2023 18:58:35 +0200 Subject: [PATCH 2/2] fix --- src/utils/sourcemaps/inject.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 22d813b2a9..21e91affdb 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -19,7 +19,7 @@ const SOURCEMAP_DEBUGID_KEY: &str = "debug_id"; const DEBUGID_COMMENT_PREFIX: &str = "//# debugId"; lazy_static! { - static ref USE_PRAGMA_RE: Regex = Regex::new(r#""use \w+";|'use \w+';"#).unwrap(); + static ref USE_PRAGMA_RE: Regex = Regex::new(r#"^"use \w+";|^'use \w+';"#).unwrap(); } fn print_section_with_debugid(