Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Using .addPhrase with Angular script optimization causes error that prevents Angular from bootstrapping #53

Open
2 of 5 tasks
cody-01 opened this issue Feb 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@cody-01
Copy link

cody-01 commented Feb 6, 2024

Expected behavior

I expected .addPhrase to include my added obscene term and build properly.

Actual behavior

Using .addPhrase in an Angular component and optimization: scripts = true in angular.json's build config causes the following error:
Cannot read properties of undefined (reading 'Literal');

This error prevented Angular from bootstrapping

Minimal reproducible example

Add this block to angular.json. "scripts: true" being the one that creates the issue. Seems like something to do with minification.

"optimization": { "styles": { "minify": true, "inlineCritical": true }, "scripts": true, "fonts": true },

Import the package to a component.
import { DataSet, RegExpMatcher, englishDataset, englishRecommendedTransformers, pattern } from 'obscenity';

In ngOnInit, add custom phrases to the DataSet

    const customDataSet = new DataSet()
      .addAll(englishDataset)
      .addPhrase((phrase) => phrase.addPattern(pattern`|damn|`))
      .addPhrase((phrase) => phrase.addPattern(pattern`|hell|`).addWhitelistedTerm('hello'));

    this.matcher = new RegExpMatcher({
      ...customDataSet.build(),
      ...englishRecommendedTransformers,
    });

...

Steps to reproduce

NOTE: This works fine in v0.1.4

  • Configure you Angular project to optimize scripts (minify) in the angular.json file
  • Using an Angular component...
  • Import englishDataset and DataSet
  • In ngOnInit, create a custom dataset that starts with the englishDataset
  • Add custom phrases to that DataSet using addPhrase => addPattern
  • Notice error: Cannot read properties of undefined (reading 'Literal');

Additional context

No response

Node.js version

v18.12.1

Obscenity version

v0.2.0

Priority

  • Low
  • Medium
  • High

Terms

  • I agree to follow the project's Code of Conduct.
  • I have searched existing issues for similar reports.
@cody-01 cody-01 added the bug Something isn't working label Feb 6, 2024
@jo3-l
Copy link
Owner

jo3-l commented Feb 6, 2024

Please provide a MRE and steps to reproduce.

Edit: Thanks for the repro, I will try to take a look at this when I can, though this is almost certainly an upstream issue as opposed to a bug in the Obscenity package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants